Skip to content

Commit 75b67ec

Browse files
authored
Merge pull request #47334 from phillip-kruger/devui_agroal_fixes
Devui agroal fixes
2 parents 7599722 + 455caa6 commit 75b67ec

File tree

2 files changed

+53
-25
lines changed

2 files changed

+53
-25
lines changed

extensions/agroal/deployment/src/main/resources/dev-ui/qwc-agroal-datasource.js

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
156156
_tables: {state: true},
157157
_selectedTable: {state: true},
158158
_selectedTableIndex:{state: true},
159-
_selectedTableCols:{state: false},
159+
_selectedTableCols:{state: true},
160160
_currentSQL: {state: true},
161161
_currentDataSet: {state: true},
162162
_isWatching: {state: true},
@@ -524,36 +524,53 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
524524
const value = item[columnName];
525525
if(value){
526526
let colDef = this._selectedTableCols.get(columnName);
527-
let colType = colDef.columnType.toLowerCase();
527+
if(colDef){
528+
let colType = colDef.columnType.toLowerCase();
528529

529-
if(colDef.binary){
530-
const byteCharacters = atob(value);
531-
const byteNumbers = new Array(byteCharacters.length);
532-
for (let i = 0; i < byteCharacters.length; i++) {
533-
byteNumbers[i] = byteCharacters.charCodeAt(i);
534-
}
535-
const byteArray = new Uint8Array(byteNumbers);
536-
537-
const blob = new Blob([byteArray], { type: 'application/octet-stream' });
538-
const url = URL.createObjectURL(blob);
539-
540-
return html`<a class="download" href="${url}" download="download">download</span>`;
541-
}else if(colType === "bool" || colType === "boolean"){ // TODO: Can we do int(1) and asume this will be a boolean ?
542-
if(value && value === "true"){
543-
return html`<vaadin-icon style="color: var(--lumo-contrast-50pct);" title="${value}" icon="font-awesome-regular:square-check"></vaadin-icon>`;
530+
if(colDef.binary){
531+
return this._renderBinaryCell(value, colType);
544532
}else {
545-
return html`<vaadin-icon style="color: var(--lumo-contrast-50pct);" title="${value}" icon="font-awesome-regular:square"></vaadin-icon>`;
546-
}
547-
} else {
548-
if(value.startsWith("http://") || value.startsWith("https://")){
549-
return html`<a href="${value}" target="_blank">${value}</a>`;
550-
}else{
551-
return html`<span>${value}</span>`;
533+
return this._renderTextCell(value, colType);
552534
}
553535
}
554536
}
555537
}
556538

539+
_renderTextCell(value, colType){
540+
if(colType === "bool" || colType === "boolean"){ // TODO: Can we do int(1) and asume this will be a boolean ?
541+
if(value && value === "true"){
542+
return html`<vaadin-icon style="color: var(--lumo-contrast-50pct);" title="${value}" icon="font-awesome-regular:square-check"></vaadin-icon>`;
543+
}else {
544+
return html`<vaadin-icon style="color: var(--lumo-contrast-50pct);" title="${value}" icon="font-awesome-regular:square"></vaadin-icon>`;
545+
}
546+
} else {
547+
if(value.startsWith("http://") || value.startsWith("https://")){
548+
return html`<a href="${value}" target="_blank">${value}</a>`;
549+
}else{
550+
return html`<span>${value}</span>`;
551+
}
552+
}
553+
}
554+
555+
_renderBinaryCell(value, colType){
556+
try {
557+
const byteCharacters = atob(value);
558+
const byteNumbers = new Array(byteCharacters.length);
559+
for (let i = 0; i < byteCharacters.length; i++) {
560+
byteNumbers[i] = byteCharacters.charCodeAt(i);
561+
}
562+
const byteArray = new Uint8Array(byteNumbers);
563+
564+
const blob = new Blob([byteArray], { type: 'application/octet-stream' });
565+
const url = URL.createObjectURL(blob);
566+
567+
return html`<a class="download" href="${url}" download="download">download</span>`;
568+
} catch (e) {
569+
// Here try a normal render. Sometimes Java objects can render in String format (eg. UUID)
570+
return this._renderTextCell(value, colType);
571+
}
572+
}
573+
557574
_watch(){
558575
this._isWatching = true;
559576
this._watchId = setInterval(() => {
@@ -579,6 +596,7 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
579596
}
580597

581598
_onTableChanged(event){
599+
this._fetchTableDefinitions();
582600
this._selectedTableIndex = event.detail.value;
583601
this._selectedTable = this._tables[this._selectedTableIndex];
584602
this._clearSqlInput();

extensions/agroal/runtime-dev/src/main/java/io/quarkus/agroal/runtime/dev/ui/DatabaseInspector.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ public DataSet executeSQL(String datasource, String sql, Integer pageNumber, Int
197197
Map<String, String> row = new HashMap<>();
198198
for (int i = 1; i <= columnCount; i++) {
199199
String columnName = metaData.getColumnName(i);
200-
boolean isBinary = isBinary(metaData.getColumnType(i));
200+
boolean isBinary = isBinary(metaData.getColumnType(i),
201+
metaData.getColumnClassName(i));
201202
if (!isBinary) {
202203
Object columnValue = resultSet.getObject(i);
203204
row.put(columnName, String.valueOf(columnValue));
@@ -366,6 +367,15 @@ private boolean isAllowedDatabase(AgroalDataSource ads) {
366367
return false;
367368
}
368369

370+
private boolean isBinary(int dataType, String javaClassName) {
371+
372+
// Some java classes can be handled as String
373+
if (java.util.UUID.class.getName().equals(javaClassName)) {
374+
return false;
375+
}
376+
return isBinary(dataType);
377+
}
378+
369379
private boolean isBinary(int dataType) {
370380
return dataType == Types.BLOB ||
371381
dataType == Types.VARBINARY ||

0 commit comments

Comments
 (0)