use of org.pentaho.database.model.DatabaseConnection in project pentaho-platform by pentaho.
the class PooledDatasourceHelperTest method testCreateDatasourceNoClassName.
@Test
public void testCreateDatasourceNoClassName() throws Exception {
DatabaseDialectService dialectService = new DatabaseDialectService(false);
final DatabaseTypeHelper databaseTypeHelper = new DatabaseTypeHelper(dialectService.getDatabaseTypes());
final DatabaseConnection con = new DatabaseConnection();
con.setId("Postgres");
con.setName("Postgres");
con.setAccessType(DatabaseAccessType.NATIVE);
con.setDatabaseType(databaseTypeHelper.getDatabaseTypeByShortName("GENERIC"));
con.setUsername("pentaho_user");
con.setPassword("password");
final HashMap<String, String> attrs = new HashMap<>();
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "");
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_URL, "jdbc:postgresql://localhost:5432/hibernate");
con.setAttributes(attrs);
try {
PooledDatasourceHelper.convert(con, () -> dialectService);
fail("Expecting the exception to be thrown");
} catch (DBDatasourceServiceException ex) {
assertNotNull(ex);
}
}
use of org.pentaho.database.model.DatabaseConnection in project pentaho-platform by pentaho.
the class PooledDatasourceHelperTest method testCreateDatasourceNoDialect.
@Test
public void testCreateDatasourceNoDialect() throws Exception {
DatabaseDialectService dialectService = new DatabaseDialectService(false);
final DatabaseConnection con = new DatabaseConnection();
con.setId("Postgres");
con.setName("Postgres");
con.setAccessType(DatabaseAccessType.NATIVE);
con.setUsername("pentaho_user");
con.setPassword("password");
final HashMap<String, String> attrs = new HashMap<>();
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "org.postgresql.Driver");
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_URL, "jdbc:postgresql://localhost:5432/hibernate");
con.setAttributes(attrs);
try {
PooledDatasourceHelper.convert(con, () -> dialectService);
fail("Expecting the exception to be thrown");
} catch (DBDatasourceServiceException ex) {
assertNotNull(ex);
}
}
use of org.pentaho.database.model.DatabaseConnection in project pentaho-platform by pentaho.
the class DatabaseHelper method databaseMetaToDatabaseConnection.
public IDatabaseConnection databaseMetaToDatabaseConnection(final DatabaseMeta databaseMeta) {
IDatabaseConnection databaseConnection = new DatabaseConnection();
databaseConnection.setDatabaseType(databaseTypeHelper.getDatabaseTypeByShortName(databaseMeta.getDatabaseTypeDesc()));
databaseConnection.setName(databaseMeta.getName());
if (databaseMeta.getObjectId() != null) {
databaseConnection.setId(databaseMeta.getObjectId().getId());
}
String accessType = databaseMeta.getAccessTypeDesc();
// This is a special case with some PDI connections
if (accessType != null && accessType.contains("Native")) {
accessType = DatabaseAccessType.NATIVE.getName();
} else if (accessType != null && accessType.equals(", ")) {
accessType = DatabaseAccessType.JNDI.getName();
}
databaseConnection.setAccessType(accessType != null ? DatabaseAccessType.getAccessTypeByName(accessType) : null);
databaseConnection.setHostname(databaseMeta.getHostname());
databaseConnection.setDatabaseName(databaseMeta.getDatabaseName());
databaseConnection.setDatabasePort(databaseMeta.getDatabasePortNumberString());
databaseConnection.setUsername(databaseMeta.getUsername());
databaseConnection.setPassword(databaseMeta.getPassword());
databaseConnection.setInformixServername(databaseMeta.getServername());
databaseConnection.setDataTablespace(databaseMeta.getDataTablespace());
databaseConnection.setIndexTablespace(databaseMeta.getIndexTablespace());
databaseConnection.setConnectSql(databaseMeta.getConnectSQL());
databaseConnection.setInitialPoolSize(databaseMeta.getInitialPoolSize());
databaseConnection.setMaximumPoolSize(databaseMeta.getMaximumPoolSize());
databaseConnection.setUsingConnectionPool(databaseMeta.isUsingConnectionPool());
databaseConnection.setForcingIdentifiersToLowerCase(databaseMeta.isForcingIdentifiersToLowerCase());
databaseConnection.setForcingIdentifiersToUpperCase(databaseMeta.isForcingIdentifiersToUpperCase());
databaseConnection.setQuoteAllFields(databaseMeta.isQuoteAllFields());
databaseConnection.setUsingDoubleDecimalAsSchemaTableSeparator(databaseMeta.isUsingDoubleDecimalAsSchemaTableSeparator());
Map<String, String> attributeMap = new HashMap<String, String>();
for (Entry<Object, Object> entry : databaseMeta.getAttributes().entrySet()) {
attributeMap.put((String) entry.getKey(), (String) entry.getValue());
}
databaseConnection.setAttributes(attributeMap);
Map<String, String> connectionPoolingMap = new HashMap<String, String>();
for (Entry<Object, Object> entry : databaseMeta.getConnectionPoolingProperties().entrySet()) {
connectionPoolingMap.put((String) entry.getKey(), (String) entry.getValue());
}
databaseConnection.setConnectionPoolingProperties(connectionPoolingMap);
databaseConnection.setExtraOptions(databaseMeta.getExtraOptions());
return databaseConnection;
}
use of org.pentaho.database.model.DatabaseConnection in project pentaho-platform by pentaho.
the class DatabaseHelper method dataNodeToDatabaseConnection.
public IDatabaseConnection dataNodeToDatabaseConnection(final Serializable id, final String name, final DataNode rootNode) {
IDatabaseConnection databaseConnection = new DatabaseConnection();
String databaseType = getString(rootNode, PROP_TYPE);
databaseConnection.setDatabaseType(databaseType != null ? databaseTypeHelper.getDatabaseTypeByShortName(databaseType) : null);
databaseConnection.setName(name);
if (id != null) {
databaseConnection.setId(id.toString());
}
String accessType = getString(rootNode, PROP_CONTYPE);
// This is a special case with some PDI connections
if (accessType != null && accessType.contains("Native")) {
accessType = DatabaseAccessType.NATIVE.getName();
} else if (accessType != null && accessType.equals(", ")) {
accessType = DatabaseAccessType.JNDI.getName();
}
databaseConnection.setAccessType(accessType != null ? DatabaseAccessType.getAccessTypeByName(accessType) : null);
databaseConnection.setHostname(getString(rootNode, PROP_HOST_NAME));
databaseConnection.setDatabaseName(getString(rootNode, PROP_DATABASE_NAME));
databaseConnection.setDatabasePort(getString(rootNode, PROP_PORT));
databaseConnection.setUsername(getString(rootNode, PROP_USERNAME));
databaseConnection.setPassword(decryptPassword(getString(rootNode, PROP_PASSWORD)));
databaseConnection.setInformixServername(getString(rootNode, PROP_SERVERNAME));
databaseConnection.setDataTablespace(getString(rootNode, PROP_DATA_TBS));
databaseConnection.setIndexTablespace(getString(rootNode, PROP_INDEX_TBS));
databaseConnection.setConnectSql(getString(rootNode, PROP_CONNECT_SQL));
databaseConnection.setInitialPoolSize(getInt(rootNode, PROP_INITIAL_POOL_SIZE));
databaseConnection.setMaximumPoolSize(getInt(rootNode, PROP_MAX_POOL_SIZE));
databaseConnection.setUsingConnectionPool(getBoolean(rootNode, PROP_IS_POOLING));
databaseConnection.setForcingIdentifiersToLowerCase(getBoolean(rootNode, PROP_IS_FORCING_TO_LOWER));
databaseConnection.setForcingIdentifiersToUpperCase(getBoolean(rootNode, PROP_IS_FORCING_TO_UPPER));
databaseConnection.setQuoteAllFields(getBoolean(rootNode, PROP_IS_QUOTE_FIELDS));
databaseConnection.setUsingDoubleDecimalAsSchemaTableSeparator(getBoolean(rootNode, PROP_IS_DECIMAL_SEPERATOR));
// Also, load all the properties we can find...
DataNode attrNode = rootNode.getNode(NODE_ATTRIBUTES);
if (attrNode != null) {
for (DataProperty property : attrNode.getProperties()) {
String code = property.getName();
String attribute = property.getString();
databaseConnection.getAttributes().put(code, // $NON-NLS-1$
(attribute == null || attribute.length() == 0) ? "" : attribute);
}
}
// Also, load any pooling params
attrNode = rootNode.getNode(NODE_POOLING_PROPS);
if (attrNode != null) {
for (DataProperty property : attrNode.getProperties()) {
String code = property.getName();
String attribute = property.getString();
databaseConnection.getConnectionPoolingProperties().put(code, // $NON-NLS-1$
(attribute == null || attribute.length() == 0) ? "" : attribute);
}
}
// Load extra options
attrNode = rootNode.getNode(NODE_EXTRA_OPTIONS);
if (attrNode != null) {
for (DataProperty property : attrNode.getProperties()) {
String code = property.getName();
String attribute = property.getString();
databaseConnection.getExtraOptions().put(code, // $NON-NLS-1$
(attribute == null || attribute.length() == 0) ? "" : attribute);
}
}
attrNode = rootNode.getNode(NODE_EXTRA_OPTIONS_ORDER);
if (attrNode != null) {
for (DataProperty property : attrNode.getProperties()) {
String code = property.getName();
String attribute = property.getString();
databaseConnection.getExtraOptionsOrder().put(code, // $NON
(attribute == null || attribute.length() == 0) ? "" : attribute);
}
}
return databaseConnection;
}
use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.
the class LegacyDatasourceConverter method unmarshal.
/**
* Convert textual data back into an object.
*
* @param reader The stream to read the text from.
* @param context
* @return The resulting object.
*/
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
MultiTableDatasourceDTO resultDTO = new MultiTableDatasourceDTO();
while (reader.hasMoreChildren()) {
reader.moveDown();
String nodeName = reader.getNodeName();
if (nodeName.equalsIgnoreCase("datasourceName")) {
String value = reader.getValue();
resultDTO.setDatasourceName(value);
} else if (nodeName.equalsIgnoreCase("selectedConnection")) {
String connectionClass = reader.getAttribute("class");
if (connectionClass != null) {
DatabaseConnection databaseConnection = new DatabaseConnection();
if (connectionClass.equals("org.pentaho.platform.dataaccess.datasource.beans.Connection")) {
while (reader.hasMoreChildren()) {
reader.moveDown();
nodeName = reader.getNodeName();
if (reader.getNodeName().equalsIgnoreCase("name")) {
String databaseName = reader.getValue();
databaseConnection.setName(databaseName);
databaseConnection.setId(databaseName);
} else if (reader.getNodeName().equalsIgnoreCase("username")) {
databaseConnection.setUsername(reader.getValue());
} else if (reader.getNodeName().equalsIgnoreCase("password")) {
databaseConnection.setPassword(reader.getValue());
} else if (reader.getNodeName().equalsIgnoreCase("url")) {
ParsedJdbcUrl parsedJdbcUrl = new ParsedJdbcUrl(reader.getValue());
databaseConnection.setHostname(parsedJdbcUrl.getHostname());
databaseConnection.setDatabasePort(parsedJdbcUrl.getPort());
databaseConnection.setDatabaseName(parsedJdbcUrl.getDatabaseName());
databaseConnection.setDatabaseType(resolveDatabaseType(parsedJdbcUrl.getJdbcPrefix()));
}
reader.moveUp();
}
resultDTO.setSelectedConnection(databaseConnection);
} else {
// instantiate the class specified
try {
Class databaseConnectionClass = Class.forName(connectionClass);
IDatabaseConnection databaseConnectionInstance = (IDatabaseConnection) context.convertAnother(resultDTO, databaseConnectionClass);
resultDTO.setSelectedConnection(databaseConnectionInstance);
} catch (ClassNotFoundException e) {
// not going to work anyway, set empty connection for now
resultDTO.setSelectedConnection(new DatabaseConnection());
}
}
}
} else if (nodeName.equalsIgnoreCase("schemaModel")) {
SchemaModel schemaModel = (SchemaModel) context.convertAnother(resultDTO, SchemaModel.class);
if (schemaModel != null) {
resultDTO.setSchemaModel(schemaModel);
}
} else if (nodeName.equalsIgnoreCase("selectedTables")) {
List<String> selectedTables = (List<String>) context.convertAnother(resultDTO, ArrayList.class);
if (selectedTables != null) {
resultDTO.setSelectedTables(selectedTables);
}
} else if (nodeName.equalsIgnoreCase("doOlap")) {
resultDTO.setDoOlap(Boolean.valueOf(reader.getValue()));
}
reader.moveUp();
}
return resultDTO;
}
Aggregations