use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class JDBCMap method getRecords.
/*
* (non-Javadoc)
*
* @see com.dexels.navajo.adapter.JDBCMappable#getRecords()
*/
@Override
public Binary getRecords() throws UserException {
ResultSet rs = null;
File tempFile;
try {
tempFile = File.createTempFile("sqlmap_records", "navajo");
} catch (IOException e1) {
throw new UserException("Temp file faillure", e1);
}
try (FileOutputStream fos = new FileOutputStream(tempFile);
OutputStreamWriter fw = new OutputStreamWriter(fos, StandardCharsets.UTF_8)) {
Binary b = null;
rs = getDBResultSet(false);
int columns = 0;
ResultSetMetaData meta = null;
try {
meta = rs.getMetaData();
columns = meta.getColumnCount();
if (this.showHeader) {
for (int j = 0; j < columns; j++) {
String column = meta.getColumnLabel(j + 1);
if (j == 0) {
fw.write(column);
} else {
fw.write(this.separator + column);
}
}
fw.write("\n");
}
} catch (Exception e) {
logger.error("Error writing output binary", e);
}
while (rs.next()) {
for (int j = 1; j <= columns; j++) {
String value = (rs.getObject(j) != null ? rs.getString(j) + "" : "");
if (j == 1) {
fw.write(value);
} else {
fw.write(this.separator + value);
}
}
fw.write("\n");
}
fw.flush();
b = new Binary(tempFile, false);
return b;
} catch (Exception ioe) {
throw new UserException(-1, ioe.getMessage(), ioe);
} finally {
if (rs != null) {
try {
rs.close();
rs = null;
resetAll();
} catch (SQLException e) {
logger.error("Error writing output binary", e);
}
}
if (tempFile != null) {
try {
Files.deleteIfExists(tempFile.toPath());
} catch (Exception ioe2) {
logger.error("Error writing output binary", ioe2);
}
}
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class JDBCMap method resetAll.
protected void resetAll() throws UserException {
this.query = this.update = null;
try {
if (this.statement != null) {
this.statement.close();
this.statement = null;
}
} catch (Exception e) {
AuditLog.log("SQLMap", e.getMessage(), Level.SEVERE, (myAccess != null ? myAccess.accessID : "unknown access"));
throw new UserException(-1, e.getMessage());
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class GrusProviderImpl method getDatabaseIdentifier.
@Override
public String getDatabaseIdentifier(String instance, String name) throws UserException {
DataSource dataSourceInstance = null;
dataSourceInstance = getInstanceDataSource(instance, name);
Map<String, Object> settings = settingsMap.get(dataSourceInstance);
if (settings == null && dataSourceInstance == null) {
settings = defaultSettingsMap.get(name);
}
if (settings == null) {
throw new UserException(-1, "Could not find settings for tenant-less datasource: " + name + " available (tenant-less) datasources: " + defaultSettingsMap.keySet());
}
String componentName = (String) settings.get("component.name");
if (componentName.endsWith("oracle")) {
return SQLMapConstants.ORACLEDB;
} else if (componentName.endsWith("mysql")) {
return SQLMapConstants.MYSQLDB;
} else if (componentName.endsWith("postgresql")) {
return SQLMapConstants.POSTGRESDB;
}
return null;
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class GrusProviderImpl method requestConnection.
@Override
public GrusConnection requestConnection(String instance, String name) throws UserException {
DataSource dataSourceInstance = null;
dataSourceInstance = getInstanceDataSource(instance, name);
Map<String, Object> settings = settingsMap.get(dataSourceInstance);
if (settings == null && dataSourceInstance == null) {
settings = defaultSettingsMap.get(name);
if (settings == null) {
throw new UserException(-1, "Could not find settings for tenant-less datasource: " + name + " available (tenant-less) datasources: " + defaultSettingsMap.keySet());
}
dataSourceInstance = defaultDataSources.get(name);
}
int id = connectionCounter.getAndIncrement();
GrusConnection gc;
try {
gc = new GrusDataSource(id, dataSourceInstance, settings, this);
} catch (Exception e) {
throw new UserException(-1, "Could not create datasource connection for: " + instance + " and name: " + name, e);
}
grusIds.put((long) id, gc);
Map<DataSource, Integer> currentMap = userThreadLocal.get();
if (currentMap == null) {
currentMap = new HashMap<>();
}
currentMap.put(dataSourceInstance, id);
userThreadLocal.set(currentMap);
return gc;
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class GrusProviderImpl method getInstanceDataSourceSettings.
@Override
public Map<String, Object> getInstanceDataSourceSettings(String instance, String name) throws UserException {
DataSource dataSourceInstance = null;
dataSourceInstance = getInstanceDataSource(instance, name);
Map<String, Object> settings = settingsMap.get(dataSourceInstance);
if (settings == null && dataSourceInstance == null) {
settings = defaultSettingsMap.get(name);
if (settings == null) {
throw new UserException(-1, "Could not find settings for tenant-less datasource: " + name + " available (tenant-less) datasources: " + defaultSettingsMap.keySet());
}
}
return settings;
}
Aggregations