Search in sources :

Example 26 with IDatabasePlatform

use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.

the class AbstractXmlPublisherExtensionPoint method readData.

protected List<String[]> readData(final Table table, String[] args) {
    final IDatabasePlatform platform = engine.getDatabasePlatform();
    List<String[]> rows = new ArrayList<String[]>();
    final String[] columnNames = table.getColumnNames();
    if (columnNames != null && columnNames.length > 0) {
        StringBuilder builder = new StringBuilder("select ");
        for (int i = 0; i < columnNames.length; i++) {
            String columnName = columnNames[i];
            if (i > 0) {
                builder.append(",");
            }
            builder.append(columnName);
        }
        builder.append(" from ").append(table.getName()).append(" where ");
        for (int i = 0; i < groupByColumnNames.size(); i++) {
            String columnName = groupByColumnNames.get(i);
            if (i > 0 && i < groupByColumnNames.size()) {
                builder.append(" and ");
            }
            builder.append(columnName).append("=?");
        }
        ISqlTemplate template = platform.getSqlTemplate();
        Object[] argObjs = platform.getObjectValues(engine.getSymmetricDialect().getBinaryEncoding(), args, table.getColumnsWithName(groupByColumnNames.toArray(new String[groupByColumnNames.size()])));
        rows = template.query(builder.toString(), new ISqlRowMapper<String[]>() {

            @Override
            public String[] mapRow(Row row) {
                return platform.getStringValues(engine.getSymmetricDialect().getBinaryEncoding(), table.getColumns(), row, false, false);
            }
        }, argObjs);
    }
    return rows;
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) ArrayList(java.util.ArrayList) Row(org.jumpmind.db.sql.Row) IExtensionPoint(org.jumpmind.extension.IExtensionPoint) INodeGroupExtensionPoint(org.jumpmind.symmetric.ext.INodeGroupExtensionPoint) ISqlRowMapper(org.jumpmind.db.sql.ISqlRowMapper)

Example 27 with IDatabasePlatform

use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.

the class AbstractTest method getWebServer.

protected SymmetricWebServer getWebServer(String name) {
    try {
        if (!webServers.containsKey(name)) {
            EnvironmentSpecificProperties properties = new EnvironmentSpecificProperties(new URL[] { getResource(DbTestUtils.DB_TEST_PROPERTIES) }, "test." + name, new String[] { name });
            properties.putAll(getProperties(name));
            File rootDir = new File("target/" + name);
            FileUtils.deleteDirectory(rootDir);
            rootDir.mkdirs();
            File engineDir = new File(rootDir, "engines");
            engineDir.mkdirs();
            File rootPropertiesFile = new File(engineDir, "root.properties");
            FileOutputStream fos = new FileOutputStream(rootPropertiesFile);
            properties.store(fos, "unit tests");
            fos.close();
            System.setProperty(SystemConstants.SYSPROP_WAIT_FOR_DATABASE, "false");
            System.setProperty(SystemConstants.SYSPROP_ENGINES_DIR, engineDir.getAbsolutePath());
            System.setProperty(SystemConstants.SYSPROP_WEB_DIR, "src/main/deploy/web");
            ISymmetricEngine engine = null;
            int tries = 2;
            do {
                /** 
                     * Firebird is flaky.  Trying to work around it.
                     */
                try {
                    engine = new ClientSymmetricEngine(properties);
                } catch (Exception ex) {
                    log.warn("Failed to create engine on the first try.  Trying again.  The root cause of the first failure was: ", ex);
                    tries--;
                    AppUtils.sleep(30000);
                }
            } while (tries > 0 && engine == null);
            IDatabasePlatform platform = engine.getDatabasePlatform();
            engine.getStagingManager().clean(0);
            engine.uninstall();
            Database database = platform.getDdlReader().readTables(platform.getDefaultCatalog(), platform.getDefaultSchema(), new String[] { "TABLE" });
            platform.dropDatabase(database, true);
            Table[] tables = getTables(name);
            if (tables != null) {
                platform.alterCaseToMatchDatabaseDefaultCase(tables);
                platform.createTables(false, true, tables);
            }
            engine.destroy();
            SymmetricWebServer server = new SymmetricWebServer();
            server.setJmxEnabled(false);
            server.setHttpPort(port);
            log.info("Starting " + name + " on port " + port);
            server.setJoin(false);
            server.start();
            server.waitForEnginesToComeOnline(240000);
            webServers.put(name, server);
            port += 200;
        }
        return webServers.get(name);
    } catch (IOException e) {
        throw new IoException(e);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) Table(org.jumpmind.db.model.Table) EnvironmentSpecificProperties(org.jumpmind.properties.EnvironmentSpecificProperties) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IOException(java.io.IOException) IoException(org.jumpmind.exception.IoException) InterruptedException(org.jumpmind.exception.InterruptedException) IOException(java.io.IOException) SymmetricWebServer(org.jumpmind.symmetric.SymmetricWebServer) FileOutputStream(java.io.FileOutputStream) ClientSymmetricEngine(org.jumpmind.symmetric.ClientSymmetricEngine) Database(org.jumpmind.db.model.Database) IoException(org.jumpmind.exception.IoException) File(java.io.File)

Aggregations

IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)27 Table (org.jumpmind.db.model.Table)13 Database (org.jumpmind.db.model.Database)9 Test (org.junit.Test)9 AbstractServiceTest (org.jumpmind.symmetric.service.impl.AbstractServiceTest)8 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)7 DatabaseInfo (org.jumpmind.db.platform.DatabaseInfo)6 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)6 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)6 DbExport (org.jumpmind.symmetric.io.data.DbExport)6 DbImport (org.jumpmind.symmetric.io.data.DbImport)6 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)5 IExtensionService (org.jumpmind.symmetric.service.IExtensionService)5 IParameterService (org.jumpmind.symmetric.service.IParameterService)5 Column (org.jumpmind.db.model.Column)4 Before (org.junit.Before)4 File (java.io.File)3 DmlStatement (org.jumpmind.db.sql.DmlStatement)3 Row (org.jumpmind.db.sql.Row)3 SqlException (org.jumpmind.db.sql.SqlException)3