Commit 7061c12b authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Fixes, added keep alive for conversation

parent 151135a3
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.37</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
+24 −18
Original line number Diff line number Diff line
@@ -22,13 +22,15 @@
 */
package it.inaf.ia2.tsm.api;

import it.inaf.ia2.tsm.api.contract.DatabaseType;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import it.inaf.ia2.tsm.api.contract.DatabaseType;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.postgresql.ds.PGPoolingDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This class is used to silently manage the possibility to have separate data
@@ -44,6 +46,7 @@ import org.postgresql.ds.PGPoolingDataSource;
public class DBWrapper implements Serializable {

    private static final long serialVersionUID = 1721030677924066695L;
    private final static Logger log = LoggerFactory.getLogger(DBWrapper.class);

    // Same credentials
    private Credentials credentials;
@@ -182,30 +185,33 @@ public class DBWrapper implements Serializable {
        }

        private DataSource createDataSource(Credentials credentials) {
            if (credentials.getDatabaseType() == DatabaseType.MYSQL) {

                MysqlDataSource ds = new MysqlDataSource();
            switch (credentials.getDatabaseType()) {

                ds.setServerName(credentials.getHostname());
                ds.setPortNumber(credentials.getPort());
                ds.setUser(credentials.getUsername());
                ds.setPassword(credentials.getPassword());
                case MYSQL:
                    MysqlDataSource myds = new MysqlDataSource();

                return ds;
            } else if (credentials.getDatabaseType() == DatabaseType.POSTGRES) {
                    myds.setServerName(credentials.getHostname());
                    myds.setPortNumber(credentials.getPort());
                    myds.setUser(credentials.getUsername());
                    myds.setPassword(credentials.getPassword());

                PGPoolingDataSource ds = new PGPoolingDataSource();
                    return myds;

                ds.setServerName(credentials.getHostname());
                ds.setPortNumber(credentials.getPort());
                ds.setUser(credentials.getUsername());
                ds.setPassword(credentials.getPassword());
                ds.setDatabaseName("postgres");
                case POSTGRES:
                    PGPoolingDataSource pgds = new PGPoolingDataSource();

                return ds;
            }
                    pgds.setServerName(credentials.getHostname());
                    pgds.setPortNumber(credentials.getPort());
                    pgds.setUser(credentials.getUsername());
                    pgds.setPassword(credentials.getPassword());
                    pgds.setDatabaseName(credentials.getDatabase());

                    return pgds;

                default:
                    throw new UnsupportedOperationException(credentials.getDatabaseType() + " not supported yet.");
            }
        }
    }
}
+4 −2
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import javax.sql.DataSource;
import org.postgresql.ds.PGPoolingDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -113,7 +112,10 @@ public class DaoKey {

        } else if (dbType == DatabaseType.POSTGRES) {

            String databaseName = ((PGPoolingDataSource) dataSource).getDatabaseName();
            String databaseName
                    = schemaName.equals(tapSchema.getName())
                            ? dbWrapper.getTapSchemaCredentials().getDatabase()
                            : dbWrapper.getSourceCredentials().getDatabase();

            List<Key> schemaKeys = new ArrayList<>();

+2 −0
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ log4j.appender.IA2.layout.ConversionPattern=[%c{1}]: %m%n
# Root Logger
log4j.rootLogger=WARN,AD

log4j.logger.org.apache.commons.dbcp2=DEBUG,AD

# IA2 Logger
log4j.logger.it.inaf.ia2=TRACE,IA2
log4j.additivity.it.inaf.ia2=false
+1 −6
Original line number Diff line number Diff line
@@ -22,11 +22,6 @@
 */
package it.inaf.ia2.tsm.api;

import it.inaf.ia2.tsm.api.TapSchemaFactory;
import it.inaf.ia2.tsm.api.TapSchemaImpl;
import it.inaf.ia2.tsm.api.UpdateOperations;
import it.inaf.ia2.tsm.api.DBWrapper;
import it.inaf.ia2.tsm.api.Credentials;
import it.inaf.ia2.tsm.api.contract.DatabaseType;
import it.inaf.ia2.tsm.api.contract.Column;
import it.inaf.ia2.tsm.api.contract.Key;
Loading