fix: Handle databases that do not support user-defined types
Add a null check to prevent NullPointerException when a database does not support user-defined data types.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.sdk.generators;
|
||||
|
||||
import com.intellij.database.model.DasColumn;
|
||||
import com.intellij.database.model.DasObject;
|
||||
import com.intellij.database.model.ObjectKind;
|
||||
import com.intellij.database.psi.DbObject;
|
||||
import com.intellij.database.psi.DbTable;
|
||||
@@ -63,15 +64,18 @@ public class GUtils {
|
||||
|
||||
public static void createUserDefineType(DbTable table) {
|
||||
String schemaName = table.getParent() != null ? table.getParent().getName() : "";
|
||||
DasUtil.getCatalogObject(table).getDasChildren(ObjectKind.SCHEMA).forEach(schema -> {
|
||||
if (schema.getName().equals("public") || schema.getName().equals(schemaName)) {
|
||||
schema.getDasChildren(ObjectKind.OBJECT_TYPE).forEach(domain -> {
|
||||
String domainName = domain.getName();
|
||||
String domainScript = ((DbObject) domain).getText();
|
||||
userDefType.put(domainName, getRawType(domainScript));
|
||||
});
|
||||
}
|
||||
});
|
||||
DasObject objCatalog = DasUtil.getCatalogObject(table);
|
||||
if (objCatalog != null) {
|
||||
objCatalog.getDasChildren(ObjectKind.SCHEMA).forEach(schema -> {
|
||||
if (schema.getName().equals("public") || schema.getName().equals(schemaName)) {
|
||||
schema.getDasChildren(ObjectKind.OBJECT_TYPE).forEach(domain -> {
|
||||
String domainName = domain.getName();
|
||||
String domainScript = ((DbObject) domain).getText();
|
||||
userDefType.put(domainName, getRawType(domainScript));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFieldType(DasColumn column) {
|
||||
|
||||
Reference in New Issue
Block a user