use of org.pentaho.database.model.IDatabaseConnection 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.IDatabaseConnection 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.IDatabaseConnection in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtService method getDatasource.
private IDatabaseConnection getDatasource(RepositoryFile file) throws DatasourceMgmtServiceException {
try {
if (file != null) {
NodeRepositoryFileData data = repository.getDataForRead(file.getId(), NodeRepositoryFileData.class);
IDatabaseConnection databaseConnection = databaseHelper.dataNodeToDatabaseConnection(file.getId(), file.getTitle(), data.getNode());
// databaseMeta.setPassword(passwordService.decrypt(databaseMeta.getPassword()));
return databaseConnection;
} else {
throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", "", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
""));
}
// } catch(PasswordServiceException pse) {
// throw new DatasourceMgmtServiceException(Messages.getInstance()
// .getErrorString("DatasourceMgmtService.ERROR_0008_UNABLE_TO_DECRYPT_PASSWORD"), pse ); //$NON-NLS-1$
} catch (UnifiedRepositoryException ure) {
throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", file.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
ure);
}
}
use of org.pentaho.database.model.IDatabaseConnection in project pentaho-platform by pentaho.
the class JNDIDatasourceServiceTest method setUp.
@Before
public void setUp() {
IDatabaseConnection mockConnection = mock(IDatabaseConnection.class);
// Set it up - this is a JNDI connection
when(mockConnection.getAccessType()).thenReturn(DatabaseAccessType.JNDI);
when(mockConnection.getDatabaseName()).thenReturn(dsName);
DataSource mockDs = mock(DataSource.class);
IDatasourceMgmtService mockMgmtService = mock(IDatasourceMgmtService.class);
spyService = spy(service);
try {
when(mockMgmtService.getDatasourceByName(dsName)).thenReturn(mockConnection);
} catch (DatasourceMgmtServiceException e) {
e.printStackTrace();
}
try {
doReturn(mockDs).when(spyService).getJndiDataSource(dsName);
} catch (DBDatasourceServiceException e) {
e.printStackTrace();
}
doReturn(mockMgmtService).when(spyService).getDatasourceMgmtService();
service.clearCache();
}
use of org.pentaho.database.model.IDatabaseConnection in project pentaho-platform by pentaho.
the class PooledDatasourceHelperTest method testConnectionFactory_MariaDB.
@Test
public void testConnectionFactory_MariaDB() {
IDatabaseConnection connection = mock(IDatabaseConnection.class);
doReturn(StringEscapeUtils.escapeHtml(user)).when(connection).getUsername();
doReturn(StringEscapeUtils.escapeHtml(password)).when(connection).getPassword();
ConnectionFactory factory = PooledDatasourceHelper.getConnectionFactory(connection, "jdbc:mariadb://localhost");
Properties props = (Properties) Whitebox.getInternalState(factory, "_props");
assertEquals(user, props.getProperty("user"));
assertEquals(password, props.getProperty("password"));
}
Aggregations