CB-290 Document format support redesign

This commit is contained in:
Serge Rider
2020-09-25 18:20:09 +03:00
parent 7fbc56704f
commit 5489bf971c
5 changed files with 30 additions and 29 deletions
@@ -83,14 +83,6 @@ type SQLResultColumn {
readOnlyStatus: String
}
type SQLResultSet {
id: ID!
columns: [ SQLResultColumn ]
rows: [ [ Object ] ]
# server always returns hasMoreData = false
hasMoreData: Boolean
}
type DatabaseDocument {
id: String
contentType: String
@@ -98,8 +90,12 @@ type DatabaseDocument {
data: Object
}
type SQLResultDataDocument {
documents: [DatabaseDocument]!
type SQLResultSet {
id: ID!
columns: [ SQLResultColumn ]
rows: [ [ Object ] ]
# server always returns hasMoreData = false
hasMoreData: Boolean
}
type SQLQueryResults {
@@ -111,7 +107,6 @@ type SQLQueryResults {
dataFormat: ResultDataFormat
resultSet: SQLResultSet
documents: SQLResultDataDocument
}
type SQLExecuteInfo {
@@ -243,6 +243,7 @@ public class WebSQLProcessor {
@NotNull Map<String, Object> updateValues, WebDataFormat dataFormat) throws DBWebException
{
WebSQLResultsInfo resultsInfo = contextInfo.getResults(resultsId);
WebSession webSession = contextInfo.getProcessor().getWebSession();
DBDRowIdentifier rowIdentifier = resultsInfo.getDefaultRowIdentifier();
if (rowIdentifier == null) {
@@ -254,7 +255,7 @@ public class WebSQLProcessor {
}
DBSDataManipulator dataManipulator = (DBSDataManipulator) dataContainer;
DBRProgressMonitor monitor = webSession.getProgressMonitor();
DBRProgressMonitor monitor = this.webSession.getProgressMonitor();
WebSQLExecuteInfo result = new WebSQLExecuteInfo();
try {
@@ -282,7 +283,7 @@ public class WebSQLProcessor {
Object cellRawValue = updateValues.get(String.valueOf(updateAttribute.getOrdinalPosition()));
Object realCellValue = updateAttribute.getValueHandler().getValueFromObject(session, updateAttribute, cellRawValue, false, true);
rowValues[i] = realCellValue;
finalRow[updateAttribute.getOrdinalPosition()] = WebSQLUtils.makeWebCellValue(monitor, null, realCellValue, dataFormat);
finalRow[updateAttribute.getOrdinalPosition()] = WebSQLUtils.makeWebCellValue(webSession, null, realCellValue, dataFormat);
}
for (int i = 0; i < keyAttributes.length; i++) {
DBDAttributeBinding keyAttribute = keyAttributes[i];
@@ -300,7 +301,7 @@ public class WebSQLProcessor {
updatedResultSet.setColumns(resultsInfo.getAttributes());
updatedResultSet.setRows(new Object[][]{finalRow});
WebSQLQueryResults updateResults = new WebSQLQueryResults(webSession, dataFormat);
WebSQLQueryResults updateResults = new WebSQLQueryResults(this.webSession, dataFormat);
updateResults.setUpdateRowCount(statistics.getRowsUpdated());
updateResults.setResultSet(updatedResultSet);
result.setDuration(statistics.getExecuteTime());
@@ -380,7 +381,7 @@ public class WebSQLProcessor {
Object cellRawValue = updateValues.get(String.valueOf(updateAttribute.getOrdinalPosition()));
Object realCellValue = updateAttribute.getValueHandler().getValueFromObject(session, updateAttribute, cellRawValue, false, true);
rowValues[i] = realCellValue;
finalRow[updateAttribute.getOrdinalPosition()] = WebSQLUtils.makeWebCellValue(monitor, null, realCellValue, dataFormat);
finalRow[updateAttribute.getOrdinalPosition()] = WebSQLUtils.makeWebCellValue(webSession, null, realCellValue, dataFormat);
}
for (int i = 0; i < keyAttributes.length; i++) {
DBDAttributeBinding keyAttribute = keyAttributes[i];
@@ -16,6 +16,7 @@
*/
package io.cloudbeaver.service.sql;
import io.cloudbeaver.model.session.WebSession;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBUtils;
@@ -87,6 +88,7 @@ class WebSQLQueryDataReceiver implements DBDDataReceiver {
@Override
public void fetchEnd(DBCSession session, DBCResultSet resultSet) throws DBCException {
WebSession webSession = contextInfo.getProcessor().getWebSession();
DBSEntity entity = dataContainer instanceof DBSEntity ? (DBSEntity) dataContainer : null;
try {
@@ -103,7 +105,7 @@ class WebSQLQueryDataReceiver implements DBDDataReceiver {
for (Object[] row : rows) {
for (int i = 0; i < bindings.length; i++) {
DBDAttributeBinding binding = bindings[i];
row[i] = WebSQLUtils.makeWebCellValue(session.getProgressMonitor(), binding, row[i], dataFormat);
row[i] = WebSQLUtils.makeWebCellValue(webSession, binding, row[i], dataFormat);
}
}
@@ -60,6 +60,9 @@ public class WebSQLQueryResults {
@Property
public WebSQLQueryResultSet getResultSet() {
if (dataFormat == WebDataFormat.document) {
return null;
}
return resultSet;
}
@@ -68,9 +71,9 @@ public class WebSQLQueryResults {
}
public List<WebSQLDatabaseDocument> getDocuments() throws DBCException {
// if (dataFormat != WebDataFormat.document) {
// throw new DBCException("Non-document presentation");
// }
if (dataFormat != WebDataFormat.document) {
return null;
}
if (this.resultSet == null) {
throw new DBCException("Null resultset");
}
@@ -16,12 +16,12 @@
*/
package io.cloudbeaver.service.sql;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBConstants;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.*;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.gis.DBGeometry;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.utils.ContentUtils;
@@ -37,7 +37,7 @@ public class WebSQLUtils {
private static final Log log = Log.getLog(WebSQLUtils.class);
public static Object makeWebCellValue(DBRProgressMonitor monitor, DBSTypedObject type, Object cellValue, WebDataFormat dataFormat) throws DBCException {
public static Object makeWebCellValue(WebSession session, DBSTypedObject type, Object cellValue, WebDataFormat dataFormat) throws DBCException {
if (cellValue instanceof Date) {
return CBConstants.ISO_DATE_FORMAT.format(cellValue);
}
@@ -50,41 +50,41 @@ public class WebSQLUtils {
if (dataFormat != WebDataFormat.document) {
return serializeDocumentValue((DBDDocument) dbValue);
} else {
return cellValue;
return new WebSQLDatabaseDocument(session, (DBDDocument) dbValue);
}
} else if (dbValue instanceof DBDComplexValue) {
return serializeComplexValue(monitor, (DBDComplexValue)dbValue, dataFormat);
return serializeComplexValue(session, (DBDComplexValue)dbValue, dataFormat);
} else if (dbValue instanceof DBGeometry) {
return serializeGeometryValue((DBGeometry)dbValue);
} else if (dbValue instanceof DBDContent) {
return serializeContentValue(monitor, (DBDContent)dbValue);
return serializeContentValue(session, (DBDContent)dbValue);
}
}
return cellValue;
}
private static Object serializeComplexValue(DBRProgressMonitor monitor, DBDComplexValue value, WebDataFormat dataFormat) throws DBCException {
private static Object serializeComplexValue(WebSession session, DBDComplexValue value, WebDataFormat dataFormat) throws DBCException {
if (value instanceof DBDCollection) {
DBDCollection collection = (DBDCollection) value;
int size = collection.getItemCount();
Object[] items = new Object[size];
for (int i = 0; i < size; i++) {
items[i] = makeWebCellValue(monitor, collection.getComponentType(), collection.getItem(i), dataFormat);
items[i] = makeWebCellValue(session, collection.getComponentType(), collection.getItem(i), dataFormat);
}
return items;
} else if (value instanceof DBDComposite) {
DBDComposite composite = (DBDComposite)value;
Map<String, Object> map = new LinkedHashMap<>();
for (DBSAttributeBase attr : composite.getAttributes()) {
map.put(attr.getName(), makeWebCellValue(monitor, attr, composite.getAttributeValue(attr), dataFormat));
map.put(attr.getName(), makeWebCellValue(session, attr, composite.getAttributeValue(attr), dataFormat));
}
return map;
}
return value.toString();
}
private static Object serializeContentValue(DBRProgressMonitor monitor, DBDContent value) throws DBCException {
return ContentUtils.getContentStringValue(monitor, value);
private static Object serializeContentValue(WebSession session, DBDContent value) throws DBCException {
return ContentUtils.getContentStringValue(session.getProgressMonitor(), value);
}
private static Object serializeDocumentValue(DBDDocument value) {