use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class WebCellAdapter method isDBDataprovider.
private boolean isDBDataprovider() {
if (isDBDataproviderObj == null) {
isDBDataproviderObj = Boolean.FALSE;
ITable table = view.getDataAdapterList().getFormController().getTable();
if (table instanceof Table) {
Table tableObj = (Table) table;
Iterator<Column> columns = tableObj.getColumns().iterator();
while (columns.hasNext()) {
Column col = columns.next();
ColumnInfo ci = col.getColumnInfo();
if (ci != null && ci.isExcluded()) {
continue;
}
if (col.getDataProviderID() == dataprovider) {
isDBDataproviderObj = Boolean.TRUE;
break;
}
}
Iterator<TableNode> tableNodes = view.getDataAdapterList().getApplication().getFlattenedSolution().getTableNodes(table);
while (tableNodes.hasNext()) {
TableNode tableNode = tableNodes.next();
if (tableNode != null) {
Iterator<IPersist> it2 = tableNode.getAllObjects();
while (it2.hasNext()) {
IPersist persist = it2.next();
if (persist instanceof IDataProvider && (((IDataProvider) persist).getDataProviderID() == dataprovider)) {
isDBDataproviderObj = Boolean.FALSE;
}
}
}
}
}
}
return isDBDataproviderObj.booleanValue();
}
use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class TitleStringPropertyType method toSabloComponentDefaultValue.
/*
* (non-Javadoc)
*
* @see com.servoy.j2db.server.ngclient.property.types.NGConversions.IFormElementDefaultValueToSabloComponent#toSabloComponentDefaultValue(org.sablo.
* specification.PropertyDescription, com.servoy.j2db.server.ngclient.INGFormElement, com.servoy.j2db.server.ngclient.WebFormComponent,
* com.servoy.j2db.server.ngclient.DataAdapterList)
*/
@Override
public BasicTagStringTypeSabloValue toSabloComponentDefaultValue(PropertyDescription pd, INGFormElement formElement, WebFormComponent component, DataAdapterList dataAdapterList) {
TitleStringConfig titleStringConfig = (TitleStringConfig) pd.getConfig();
String forDataprovider = titleStringConfig.getForDataprovider();
if (forDataprovider != null) {
PropertyDescription forProperty = formElement.getPropertyDescription(forDataprovider);
if (forProperty != null) {
IPropertyType<?> type = forProperty.getType();
if (type instanceof FoundsetLinkedPropertyType) {
Object config = forProperty.getConfig();
if (config instanceof FoundsetLinkedConfig && ((FoundsetLinkedConfig) config).getForFoundsetName() != null) {
String forFoundset = ((FoundsetLinkedConfig) config).getForFoundsetName();
String dataproviderID = (String) formElement.getPropertyValue(forDataprovider);
JSONObject foundsetValue = (JSONObject) formElement.getPropertyValue(forFoundset);
if (foundsetValue != null) {
String foundsetID = foundsetValue.optString(FoundsetPropertyType.FOUNDSET_SELECTOR);
INGApplication application = ((WebFormComponent) component.getUnderlyingWebObject()).getDataConverterContext().getApplication();
Form form = ((IContextProvider) component.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm();
ITable table = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(foundsetID, application, form);
if (table != null) {
Column dataproviderColumn = table.getColumn(dataproviderID);
if (dataproviderColumn != null) {
return toSabloComponentValue(dataproviderColumn.getTitle(), pd, formElement, component, dataAdapterList);
}
}
}
}
}
}
}
return null;
}
use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class FlattenedSolution method getAllDataProvidersForTable.
public Map<String, IDataProvider> getAllDataProvidersForTable(ITable table) throws RepositoryException {
if (table == null)
return null;
synchronized (this) {
if (allProvidersForTable == null)
allProvidersForTable = new ConcurrentHashMap<ITable, Map<String, IDataProvider>>(64, 0.9f, 16);
}
Map<String, IDataProvider> dataProvidersMap = allProvidersForTable.get(table);
if (dataProvidersMap == null) {
dataProvidersMap = new HashMap<String, IDataProvider>(16, 0.9f);
// 1) first the columns
Iterator<Column> columns = table.getColumns().iterator();
while (columns.hasNext()) {
Column col = columns.next();
ColumnInfo ci = col.getColumnInfo();
if (ci != null && ci.isExcluded()) {
continue;
}
dataProvidersMap.put(col.getDataProviderID(), col);
}
// 2) last the scriptcalculations and aggregates so the overlap the columns in case of stored calcs
Iterator<TableNode> tableNodes = getTableNodes(table);
while (tableNodes.hasNext()) {
TableNode tableNode = tableNodes.next();
if (tableNode != null) {
Iterator<IPersist> it2 = tableNode.getAllObjects();
while (it2.hasNext()) {
IPersist persist = it2.next();
if (persist instanceof IDataProvider) {
dataProvidersMap.put(((IDataProvider) persist).getDataProviderID(), (IDataProvider) persist);
}
}
}
}
Map<String, IDataProvider> currentValue = allProvidersForTable.putIfAbsent(table, dataProvidersMap);
if (currentValue != null)
dataProvidersMap = currentValue;
}
return dataProvidersMap;
}
use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class FlattenedSolution method getGlobalDataProviderEx.
private IDataProvider getGlobalDataProviderEx(String id, boolean quiet) throws RepositoryException {
if (id == null)
return null;
Pair<String, String> scope = ScopesUtils.getVariableScope(id);
if (scope.getLeft() != null) /* global scope */
{
// search all objects,will return globals
ScriptVariable global = AbstractBase.selectByName(getScriptVariables(scope.getLeft(), false), scope.getRight());
if (global != null) {
return global;
}
// try @enum global variables
return getEnumDataProvider(id);
}
// in case of multi-level relations we have more that 1 dot
int indx = id.lastIndexOf('.');
if (indx > 0) {
String rel_name = id.substring(0, indx);
String col = id.substring(indx + 1);
Relation[] relations = getRelationSequence(rel_name);
if (relations == null) {
return null;
}
Relation r = relations[relations.length - 1];
if (quiet) {
boolean missingSrv = true;
String ds = r.getForeignDataSource();
if (ds != null) {
String[] st = DataSourceUtilsBase.getDBServernameTablename(ds);
if (st != null && st.length == 2) {
try {
missingSrv = (r.getRootObject().getServer(st[0]) == null);
} catch (RemoteException e) {
// we are in developer here - shouldn't happen
}
}
}
if (missingSrv)
return null;
}
// TODO if this is refactord out to be resolved outside the relation also look at the DataProviderConverter
// the call from that class to flattenedSolution.getGlobalDataProvider(value);
Column[] cols = r.getForeignColumns(this);
if (cols == null || cols.length == 0)
return null;
IDataProvider c = getDataProviderForTable(getTable(r.getForeignDataSource()), col);
if (r != null && c instanceof IColumn) {
return new ColumnWrapper((IColumn) c, relations);
}
return c;
}
return null;
}
use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class FlattenedSolution method getValuelistSortRelation.
/**
* Get the internal relation that can be used to sort on this value list using the display values.
* @param valueList
* @param callingTable
* @param dataProviderID
* @param foundSetManager
* @return
* @throws RepositoryException
*/
public Relation getValuelistSortRelation(ValueList valueList, Table callingTable, String dataProviderID, IFoundSetManagerInternal foundSetManager) throws RepositoryException {
if (callingTable == null || valueList == null) {
return null;
}
String destDataSource;
Relation[] relationSequence;
String relationPrefix;
switch(valueList.getDatabaseValuesType()) {
case IValueListConstants.TABLE_VALUES:
// create an internal relation
relationSequence = null;
// $NON-NLS-1$
relationPrefix = "";
destDataSource = valueList.getDataSource();
break;
case IValueListConstants.RELATED_VALUES:
// replace the last relation in the sequence with an internal relation
relationSequence = getRelationSequence(valueList.getRelationName());
if (relationSequence == null) {
return null;
}
if (relationSequence.length > 1) {
for (Relation r : relationSequence) {
if (r.getJoinType() != INNER_JOIN) {
// outer join on the intermediate tables causes extra results that influence the sorting result
return null;
}
}
}
StringBuilder sb = new StringBuilder();
for (Relation r : relationSequence) {
sb.append('-').append(r.getName());
}
relationPrefix = sb.toString();
destDataSource = relationSequence[relationSequence.length - 1].getForeignDataSource();
break;
default:
return null;
}
if (destDataSource == null || !DataSourceUtils.isSameServer(callingTable.getDataSource(), destDataSource)) {
// do not create a cross-server relation
return null;
}
Table destTable = (Table) foundSetManager.getTable(destDataSource);
if (destTable == null) {
return null;
}
String relationName = // $NON-NLS-1$
Relation.INTERNAL_PREFIX + "VL-" + callingTable.getDataSource() + '-' + dataProviderID + relationPrefix + '-' + valueList.getName() + '-';
synchronized (this) {
Column callingColumn = callingTable.getColumn(dataProviderID);
if (callingColumn == null) {
return null;
}
Relation relation = getRelation(relationName);
if (relation == null) {
// create in internal relation
String dp;
int returnValues = valueList.getReturnDataProviders();
if ((returnValues & 1) != 0) {
dp = valueList.getDataProviderID1();
} else if ((returnValues & 2) != 0) {
dp = valueList.getDataProviderID2();
} else if ((returnValues & 4) != 0) {
dp = valueList.getDataProviderID3();
} else {
return null;
}
Column destColumn = destTable.getColumn(dp);
if (destColumn == null) {
return null;
}
// create internal value list relation
QueryTable callingQTable = new QueryTable(callingTable.getSQLName(), callingTable.getDataSource(), callingTable.getCatalog(), callingTable.getSchema());
QueryTable destQTable = new QueryTable(destTable.getSQLName(), destTable.getDataSource(), destTable.getCatalog(), destTable.getSchema());
List<ISQLTableJoin> joins = new ArrayList<ISQLTableJoin>();
ISQLTableJoin lastJoin = null;
if (relationSequence == null) {
// table values
joins.add(lastJoin = new QueryJoin(relationName, callingQTable, destQTable, new AndCondition(), LEFT_OUTER_JOIN, false));
if (// apply name as filter on column valuelist_name
valueList.getUseTableFilter()) {
lastJoin.getCondition().addCondition(new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, new QueryColumn(destQTable, DBValueList.NAME_COLUMN), valueList.getName()));
}
} else {
// related values
QueryTable primaryQTable = callingQTable;
for (int i = 0; i < relationSequence.length; i++) {
Relation r = relationSequence[i];
QueryTable foreignQTable;
if (i == relationSequence.length - 1) {
// last one
foreignQTable = destQTable;
} else {
ITable relForeignTable = getTable(r.getForeignDataSource());
if (relForeignTable == null) {
return null;
}
foreignQTable = new QueryTable(relForeignTable.getSQLName(), relForeignTable.getDataSource(), relForeignTable.getCatalog(), relForeignTable.getSchema());
}
lastJoin = SQLGenerator.createJoin(this, r, primaryQTable, foreignQTable, false, new IGlobalValueEntry() {
public Object setDataProviderValue(String dpid, Object value) {
return null;
}
public Object getDataProviderValue(String dpid) {
// A value will be added when the relation is used, see SQLGenerator.createJoin
return new Placeholder(new ObjectPlaceholderKey<int[]>(null, dpid));
}
public boolean containsDataProvider(String dpid) {
return false;
}
});
joins.add(lastJoin);
primaryQTable = foreignQTable;
}
}
// add condition for return dp id
lastJoin.getCondition().addCondition(new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, destColumn.queryColumn(destQTable), callingColumn.queryColumn(callingQTable)));
relation = getSolutionCopy().createNewRelation(new ScriptNameValidator(this), relationName, callingTable.getDataSource(), destDataSource, LEFT_OUTER_JOIN);
ISQLTableJoin join;
if (joins.size() == 1) {
join = lastJoin;
} else {
// combine joins
join = new QueryCompositeJoin(relationName, joins);
}
relation.setRuntimeProperty(Relation.RELATION_JOIN, join);
}
return relation;
}
}
Aggregations