use of org.pentaho.database.util.DatabaseTypeHelper in project pentaho-platform by pentaho.
the class PooledDatasourceHelperTest method testCreatePoolNoClassName.
@Test
public void testCreatePoolNoClassName() throws Exception {
DatabaseDialectService dialectService = new DatabaseDialectService(false);
final DatabaseTypeHelper databaseTypeHelper = new DatabaseTypeHelper(dialectService.getDatabaseTypes());
mp = new MicroPlatform(SOLUTION_PATH);
mp.defineInstance(IDatabaseDialectService.class, dialectService);
mp.start();
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.setupPooledDataSource(con);
fail("Expecting the exception to be thrown");
} catch (DBDatasourceServiceException ex) {
assertNotNull(ex);
}
}
use of org.pentaho.database.util.DatabaseTypeHelper 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.util.DatabaseTypeHelper in project data-access by pentaho.
the class DatabaseConnectionConverterTest method testConvertToXml.
@Test
public void testConvertToXml() {
DatabaseConnection dbConnection = new DatabaseConnection();
dbConnection.setId("my id");
dbConnection.setAccessType(DatabaseAccessType.NATIVE);
List<DatabaseAccessType> accessTypes = new LinkedList<DatabaseAccessType>();
accessTypes.add(DatabaseAccessType.NATIVE);
DatabaseType dbType = new DatabaseType("name", "short name", accessTypes, 100500, "helpUri");
dbConnection.setDatabaseType(dbType);
Map<String, String> extraOptions = new HashMap<String, String>();
extraOptions.put("opt", "value");
dbConnection.setExtraOptions(extraOptions);
dbConnection.setName("Best name");
dbConnection.setHostname("localhost");
dbConnection.setDatabaseName("foodmart");
dbConnection.setDatabasePort("2233");
dbConnection.setUsername("username");
dbConnection.setPassword("password");
dbConnection.setStreamingResults(true);
dbConnection.setDataTablespace("tables");
dbConnection.setIndexTablespace("indexes");
dbConnection.setSQLServerInstance("INSTANCE_0");
dbConnection.setUsingDoubleDecimalAsSchemaTableSeparator(true);
dbConnection.setInformixServername("INFORM_1");
dbConnection.addExtraOption("100", "option", "value");
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("attr1", "value");
dbConnection.setAttributes(attributes);
dbConnection.setChanged(true);
dbConnection.setQuoteAllFields(true);
dbConnection.setForcingIdentifiersToLowerCase(true);
dbConnection.setForcingIdentifiersToUpperCase(true);
dbConnection.setConnectSql("select * from 1");
dbConnection.setUsingConnectionPool(true);
dbConnection.setInitialPoolSize(3);
dbConnection.setMaximumPoolSize(9);
dbConnection.setPartitioned(true);
Map<String, String> connectionPoolingProperties = new HashMap<String, String>();
connectionPoolingProperties.put("pool", "abc");
dbConnection.setConnectionPoolingProperties(connectionPoolingProperties);
List<PartitionDatabaseMeta> partitioningInformation = new LinkedList<PartitionDatabaseMeta>();
PartitionDatabaseMeta pdm = new PartitionDatabaseMeta();
partitioningInformation.add(pdm);
dbConnection.setPartitioningInformation(partitioningInformation);
List<IDatabaseType> databaseTypes = new LinkedList<IDatabaseType>();
databaseTypes.add(dbType);
DatabaseTypeHelper dbh = new DatabaseTypeHelper(databaseTypes);
DatabaseConnectionConverter dbcc = new DatabaseConnectionConverter(dbh);
String xmlCOnnection = dbcc.convertToXml(dbConnection);
}
use of org.pentaho.database.util.DatabaseTypeHelper in project data-access by pentaho.
the class ConnectionController method init.
@Bindable
public void init() {
XulServiceCallback<List<IDatabaseType>> callback = new XulServiceCallback<List<IDatabaseType>>() {
public void error(String message, Throwable error) {
error.printStackTrace();
}
public void success(List<IDatabaseType> retVal) {
databaseTypeHelper = new DatabaseTypeHelper(retVal);
}
};
dialectService.getDatabaseTypes(callback);
saveConnectionConfirmationDialog = // $NON-NLS-1$
(XulDialog) document.getElementById("saveConnectionConfirmationDialogConnectionController");
overwriteConnectionConfirmationDialog = (XulDialog) document.getElementById("overwriteConnectionConfirmationDialogConnectionController");
renameConnectionConfirmationDialog = (XulDialog) document.getElementById("renameConnectionConfirmationDialogConnectionController");
// $NON-NLS-1$
errorDialog = (XulDialog) document.getElementById("errorDialog");
// $NON-NLS-1$
errorLabel = (XulLabel) document.getElementById("errorLabel");
// $NON-NLS-1$
successDialog = (XulDialog) document.getElementById("successDialog");
// $NON-NLS-1$
successLabel = (XulLabel) document.getElementById("successLabel");
// $NON-NLS-1$
removeConfirmationDialog = (XulDialog) document.getElementById("removeConfirmationDialogConnectionController");
// $NON-NLS-1$
successDetailsDialog = (XulDialog) document.getElementById("successDetailsDialogConnectionController");
}
use of org.pentaho.database.util.DatabaseTypeHelper in project data-access by pentaho.
the class AgileMartDatasourceHelper method getAgileMartDatasource.
private IDatabaseConnection getAgileMartDatasource(Boolean useDefault, Properties agileMartDatasourceProperties) {
IDatabaseConnection databaseConnection = new DatabaseConnection();
IDatabaseDialectService databaseDialectService = PentahoSystem.get(IDatabaseDialectService.class);
DatabaseTypeHelper databaseTypeHelper = new DatabaseTypeHelper(databaseDialectService.getDatabaseTypes());
databaseConnection.setDatabaseType(databaseTypeHelper.getDatabaseTypeByShortName(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_DATABASETYPESHORTNAME_VALUE) : agileMartDatasourceProperties.getProperty(DATABASETYPESHORTNAME)));
String accessType = useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_ACCESS_TYPE_VALUE) : agileMartDatasourceProperties.getProperty(ACCESS_TYPE);
// This is a special case with some PDI connections
if (accessType != null && accessType.contains("Native") || accessType.equals("NATIVE")) {
accessType = DatabaseAccessType.NATIVE.getName();
} else if (accessType != null && accessType.equals(", ")) {
accessType = DatabaseAccessType.JNDI.getName();
}
databaseConnection.setAccessType(accessType != null ? DatabaseAccessType.getAccessTypeByName(accessType) : null);
databaseConnection.setName(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_NAME_VALUE) : agileMartDatasourceProperties.getProperty(NAME));
databaseConnection.setChanged(Boolean.getBoolean(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_CHANGED_VALUE) : agileMartDatasourceProperties.getProperty(CHANGED)));
databaseConnection.setDatabaseName(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_DATABASENAME_VALUE) : agileMartDatasourceProperties.getProperty(DATABASENAME));
databaseConnection.setDatabasePort(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_DATABASEPORT_VALUE) : agileMartDatasourceProperties.getProperty(DATABASEPORT));
databaseConnection.setForcingIdentifiersToLowerCase(Boolean.getBoolean(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_FORCINGIDENTIFIERSTOLOWERCASE_VALUE) : agileMartDatasourceProperties.getProperty(FORCINGIDENTIFIERSTOLOWERCASE)));
databaseConnection.setForcingIdentifiersToUpperCase(Boolean.getBoolean(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_FORCINGIDENTIFIERSTOUPPERCASE_VALUE) : agileMartDatasourceProperties.getProperty(FORCINGIDENTIFIERSTOUPPERCASE)));
databaseConnection.setHostname(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_HOSTNAME_VALUE) : agileMartDatasourceProperties.getProperty(HOSTNAME));
databaseConnection.setInitialPoolSize(Integer.valueOf(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_INITIALPOOLSIZE_VALUE) : agileMartDatasourceProperties.getProperty(INITIALPOOLSIZE)));
databaseConnection.setMaximumPoolSize(Integer.valueOf(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_MAXIMUMPOOLSIZE_VALUE) : agileMartDatasourceProperties.getProperty(MAXIMUMPOOLSIZE)));
databaseConnection.setPartitioned(Boolean.getBoolean(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_PARTITIONED_VALUE) : agileMartDatasourceProperties.getProperty(PARTITIONED)));
databaseConnection.setPassword(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_PASSWORD_VALUE) : agileMartDatasourceProperties.getProperty(PASSWORD));
databaseConnection.setUsername(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_USERNAME_VALUE) : agileMartDatasourceProperties.getProperty(USERNAME));
databaseConnection.setUsingConnectionPool(Boolean.getBoolean(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_USECONNECTIONPOOL_VALUE) : agileMartDatasourceProperties.getProperty(USECONNECTIONPOOL)));
databaseConnection.setUsingDoubleDecimalAsSchemaTableSeparator(Boolean.getBoolean(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_USINGDOUBLEDECIMALASSCHEMATABLESEPERATOR_VALUE) : agileMartDatasourceProperties.getProperty(USINGDOUBLEDECIMALASSCHEMATABLESEPERATOR)));
Map<String, String> attributes = new HashMap<String, String>();
attributes.put(ATTRIBUTE_PORT_NUMBER, useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_DATABASEPORT_VALUE) : agileMartDatasourceProperties.getProperty(DATABASEPORT));
attributes.put(ATTRIBUTE_STANDARD_CONNECTION, Boolean.FALSE.toString());
attributes.put(ATTRIBUTE_AGILE_MART_CONNECTION, Boolean.TRUE.toString());
databaseConnection.setAttributes(attributes);
return databaseConnection;
}
Aggregations