use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class SQLGenerator method createDynamicPKSetConditionForFoundset.
static SetCondition createDynamicPKSetConditionForFoundset(FoundSet foundSet, BaseQueryTable queryTable, IDataSet pks) {
Table table = (Table) foundSet.getTable();
List<Column> rowIdentColumns = table.getRowIdentColumns();
QueryColumn[] pkQueryColumns = new QueryColumn[rowIdentColumns.size()];
// getPrimaryKeys from table
for (int i = 0; i < rowIdentColumns.size(); i++) {
Column column = rowIdentColumns.get(i);
pkQueryColumns[i] = column.queryColumn(queryTable);
}
// Dynamic PK condition, the special placeholder will be updated when the foundset pk set changes
Placeholder placeHolder = new Placeholder(new TablePlaceholderKey(queryTable, SQLGenerator.PLACEHOLDER_FOUNDSET_PKS));
placeHolder.setValue(new DynamicPkValuesArray(rowIdentColumns, pks.clone()));
return new SetCondition(IBaseSQLCondition.EQUALS_OPERATOR, pkQueryColumns, placeHolder, true);
}
use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class SQLSheet method getDuplicateRecordData.
public Object[] getDuplicateRecordData(IServiceProvider app, Row toDuplicateRow) {
Object[] toDuplicate = toDuplicateRow.getRawColumnData();
SQLDescription desc = getSQLDescription(SELECT);
List<?> list = desc.getDataProviderIDsDilivery();
Object[] array = new Object[toDuplicate.length];
// $NON-NLS-1$
if (list.size() != array.length)
throw new IllegalArgumentException("Data to duplicate MUST be created with (help) of this sheet");
for (int i = 0; i < toDuplicate.length; i++) {
Object obj = toDuplicate[i];
if (obj instanceof ValueFactory.BlobMarkerValue) {
obj = toDuplicateRow.getValue(i);
} else if (obj instanceof ValueFactory.DbIdentValue && ((DbIdentValue) obj).getRow() == toDuplicateRow) {
// only create a new db ident value if that db ident value belongs to the duplicated row (== pk db ident instead a a relation db ident that has to be kept!)
obj = ValueFactory.createDbIdentValue();
}
array[i] = obj;
try {
Column c = table.getColumn((String) list.get(i));
ColumnInfo ci = c.getColumnInfo();
if (c.isDBIdentity()) {
array[i] = ValueFactory.createDbIdentValue();
} else if (ci != null && ci.hasSequence()) {
array[i] = c.getNewRecordValue(app);
}
if (ci != null && ci.hasSystemValue()) {
array[i] = c.getNewRecordValue(app);
}
} catch (Exception ex) {
Debug.error(ex);
}
}
return array;
}
use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class SQLSheet method getDefaultPKSort.
public List<SortColumn> getDefaultPKSort() {
if (table == null) {
return null;
}
if (defaultSort == null) {
List<SortColumn> ds = null;
if (table.getRowIdentColumns().size() > 1) {
// find a match with an index
for (IndexInfo index : Utils.iterate(table.getIndexes())) {
if (index.isUnique()) {
List<SortColumn> indexCols = index.getColumns();
List<Column> rowIdentColumnsCopy = new ArrayList<Column>(table.getRowIdentColumns());
boolean match = indexCols.size() == rowIdentColumnsCopy.size();
for (int c = 0; match && c < indexCols.size(); c++) {
match = rowIdentColumnsCopy.remove(indexCols.get(c).getColumn());
}
if (match) {
ds = indexCols;
break;
}
}
}
}
if (// no match on index
ds == null) {
ds = new ArrayList<SortColumn>(table.getRowIdentColumns().size());
// get key columns in db defined order
for (Column column : table.getColumns()) {
if (table.getRowIdentColumns().contains(column)) {
ds.add(new SortColumn(column));
}
}
}
defaultSort = ds;
}
return defaultSort;
}
use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class SQLSheet method getNewRowData.
/**
* Returns raw (not using column converters) row data for a new record
* @param app
* @param fs
* @return
*/
Object[] getNewRowData(IServiceProvider app, FoundSet fs) {
Object[][] creationArgs = null;
// INSERT
SQLDescription desc = getSQLDescription(SELECT);
// RequiredDataProviderIDs();
List<?> list = desc.getDataProviderIDsDilivery();
Column[] fcols = null;
Relation relation = null;
String relationName = fs.getRelationName();
if (relationName != null) {
try {
relation = app.getFlattenedSolution().getRelation(relationName);
if (relation != null) {
fcols = relation.getForeignColumns(app.getFlattenedSolution());
QuerySelect creationSQLString = fs.getCreationSqlSelect();
Placeholder ph = creationSQLString.getPlaceholder(SQLGenerator.createRelationKeyPlaceholderKey(creationSQLString.getTable(), relation.getName()));
if (ph != null && ph.isSet()) {
// a matrix as wide as the relation keys and 1 deep
creationArgs = (Object[][]) ph.getValue();
}
}
} catch (RepositoryException e) {
Debug.error(e);
}
}
Object[] array = new Object[list.size()];
for (int i = 0; i < list.size(); i++) {
try {
boolean filled = false;
Column c = table.getColumn((String) list.get(i));
if (c.isDBIdentity()) {
array[i] = ValueFactory.createDbIdentValue();
filled = true;
} else {
ColumnInfo ci = c.getColumnInfo();
if (c.getRowIdentType() != IBaseColumn.NORMAL_COLUMN && ci != null && ci.hasSequence()) {
// this is here for safety, it can happen that a form has (unwanted) still a related foundset which is created by relation based on primary key
array[i] = c.getNewRecordValue(app);
filled = true;
} else {
if (// created via relation, so fill the foreign key with foreign value
creationArgs != null && creationArgs.length != 0 && fcols != null) {
for (int j = 0; j < fcols.length; j++) {
if (c.equals(fcols[j]) && ((relation.getOperators()[j] & IBaseSQLCondition.OPERATOR_MASK) == IBaseSQLCondition.EQUALS_OPERATOR)) {
// creationArgs is a matrix as wide as the relation keys and 1 deep
array[i] = creationArgs[j][0];
filled = true;
break;
}
}
}
}
}
if (!filled) {
array[i] = c.getNewRecordValue(app);
}
} catch (Exception ex) {
Debug.error(ex);
}
}
return array;
}
use of com.servoy.j2db.persistence.Column in project servoy-client by Servoy.
the class SQLSheet method processCopyValues.
void processCopyValues(IRecordInternal s) {
SQLDescription desc = getSQLDescription(SELECT);
if (desc == null) {
return;
}
List<?> list = desc.getDataProviderIDsDilivery();
for (int i = 0; i < list.size(); i++) {
try {
String id = (String) list.get(i);
Column c = table.getColumn(id);
if (c != null) {
ColumnInfo ci = c.getColumnInfo();
if (ci != null && ci.getAutoEnterType() == ColumnInfo.LOOKUP_VALUE_AUTO_ENTER) {
String lookupDataProviderID = ci.getLookupValue();
Object obj = s.getValue(lookupDataProviderID);
if (ScopesUtils.isVariableScope(lookupDataProviderID) && !s.has(lookupDataProviderID)) {
ScriptMethod globalScriptMethod = application.getFlattenedSolution().getScriptMethod(null, lookupDataProviderID);
if (globalScriptMethod != null) {
try {
IServer server = application.getSolution().getServer(table.getServerName());
obj = application.getScriptEngine().getScopesScope().executeGlobalFunction(globalScriptMethod.getScopeName(), globalScriptMethod.getName(), new Object[] { new JSColumn(c, server, table) }, false, false);
} catch (Exception e) {
Debug.error(e);
}
}
}
// Protect to writing null to null-protected columns. An exception gets written in the log.
if (!((obj == null) && !c.getAllowNull()))
s.setValue(id, obj, false);
}
}
} catch (Exception ex) {
Debug.error(ex);
}
}
}
Aggregations