use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class TestDataSourceResource method main.
public static void main(String[] args) {
IDatabaseConnection conn = getConnectionByName(CONNECTION_NAME);
if (conn == null)
add();
else
update();
conn = getConnectionByName(CONNECTION_NAME);
if (conn != null) {
System.out.println("GetConn " + conn.getName());
delete();
}
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class TestDataSourceResource method update.
private static void update() {
init();
IDatabaseConnection connection = createConnectionObject();
String conn = (new JSONObject(connection)).toString();
System.out.println(conn);
try {
WebResource resource = client.resource(update_url);
Response result = resource.accept(MediaType.APPLICATION_JSON).entity(conn).post(Response.class);
System.out.println(result);
} catch (Exception ex) {
System.out.println("Error in update");
}
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class DatasourceInMemoryServiceHelper method getConnection.
public static SQLConnection getConnection(String connectionName) throws DatasourceServiceException {
IDatabaseConnection connection = null;
try {
ConnectionServiceImpl service = new ConnectionServiceImpl();
connection = service.getConnectionByName(connectionName);
DatabaseDialectService dialectService = new DatabaseDialectService();
IDatabaseDialect dialect = dialectService.getDialect(connection);
String driverClass = null;
if (connection.getDatabaseType().getShortName().equals("GENERIC")) {
driverClass = connection.getAttributes().get(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS);
} else {
driverClass = dialect.getNativeDriver();
}
return new SQLConnection(driverClass, dialect.getURLWithExtraOptions(connection), connection.getUsername(), connection.getPassword(), null);
} catch (ConnectionServiceException e1) {
return null;
} catch (DatabaseDialectException e) {
return null;
}
}
use of org.pentaho.database.model.IDatabaseConnection 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;
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class JdbcDatasourceResourceTest method testGetConnectionIDs.
@Test
public void testGetConnectionIDs() throws Exception {
IDatabaseConnection mockIDatabaseConnection = mock(IDatabaseConnection.class);
List<IDatabaseConnection> conns = new ArrayList<IDatabaseConnection>();
conns.add(mockIDatabaseConnection);
List<String> connStrList = new ArrayList<String>();
connStrList.add(conns.get(0).getName());
doReturn(conns).when(jdbcDatasourceResource.service).getConnections();
JaxbList<String> connections = jdbcDatasourceResource.getConnectionIDs();
verify(jdbcDatasourceResource, times(1)).getConnectionIDs();
assertEquals(connections.getList().get(0), connStrList.get(0));
}
Aggregations