Commit 62382a93 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added connection pooling on core, added ObsCore uytpe and ucd on XML model,...

Added connection pooling on core, added ObsCore uytpe and ucd on XML model, added ObsCore optional columns
parent 60551cea
Loading
Loading
Loading
Loading
+16 −0
Original line number Original line Diff line number Diff line
@@ -13,15 +13,23 @@
        <netbeans.hint.license>inaf-license-netbeans</netbeans.hint.license>
        <netbeans.hint.license>inaf-license-netbeans</netbeans.hint.license>
    </properties>
    </properties>
    <dependencies>
    <dependencies>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jdbc</artifactId>
            <version>8.5.19</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
        <dependency>
            <groupId>mysql</groupId>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.37</version>
            <version>5.1.37</version>
            <scope>runtime</scope>
        </dependency>
        </dependency>
        <dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <artifactId>postgresql</artifactId>
            <version>9.3-1104-jdbc41</version>
            <version>9.3-1104-jdbc41</version>
            <scope>runtime</scope>
        </dependency>
        </dependency>
        <dependency> 
        <dependency> 
            <groupId>org.slf4j</groupId>
            <groupId>org.slf4j</groupId>
@@ -45,6 +53,14 @@
                    <show>public</show>
                    <show>public</show>
                </configuration>
                </configuration>
            </plugin>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <trimStackTrace>false</trimStackTrace>
                </configuration>
            </plugin>
        </plugins>
        </plugins>
    </build>
    </build>
</project>
</project>
 No newline at end of file
+5 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,11 @@ public class Column extends ChildEntity<Table> {
    public final static String ARRAYSIZE_KEY = "arraysize";
    public final static String ARRAYSIZE_KEY = "arraysize";
    public final static String INDEXED_KEY = "indexed";
    public final static String INDEXED_KEY = "indexed";
    public final static String PRIMARY_KEY = "primary_key";
    public final static String PRIMARY_KEY = "primary_key";
    public final static String PRINCIPAL_KEY = "principal";
    public final static String STD_KEY = "std";
    public final static String UTYPE_KEY = "utype";
    public final static String UCD_KEY = "ucd";
    public final static String UNIT_KEY = "unit";


    private static final long serialVersionUID = 9175956487892235521L;
    private static final long serialVersionUID = 9175956487892235521L;
    private static final Logger LOG = LoggerFactory.getLogger(Column.class);
    private static final Logger LOG = LoggerFactory.getLogger(Column.class);
+0 −38
Original line number Original line Diff line number Diff line
@@ -22,10 +22,8 @@
 */
 */
package it.inaf.ia2.tsm;
package it.inaf.ia2.tsm;


import it.inaf.ia2.tsm.datalayer.Credentials;
import it.inaf.ia2.tsm.datalayer.DatabaseType;
import it.inaf.ia2.tsm.datalayer.DatabaseType;
import it.inaf.ia2.tsm.datalayer.DBWrapper;
import it.inaf.ia2.tsm.datalayer.DBWrapper;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.sql.ResultSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.ArrayList;
@@ -33,7 +31,6 @@ import java.util.Collections;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Map;
import javax.sql.DataSource;
import javax.sql.DataSource;
import org.postgresql.ds.PGPoolingDataSource;
import org.slf4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.LoggerFactory;


@@ -47,36 +44,6 @@ public class TSMUtil {


    private static final Logger LOG = LoggerFactory.getLogger(TSMUtil.class);
    private static final Logger LOG = LoggerFactory.getLogger(TSMUtil.class);


    public static DataSource createDataSource(Credentials credentials) {

        switch (credentials.getDatabaseType()) {

            case MYSQL:
                MysqlDataSource myds = new MysqlDataSource();

                myds.setServerName(credentials.getHostname());
                myds.setPortNumber(credentials.getPort());
                myds.setUser(credentials.getUsername());
                myds.setPassword(credentials.getPassword());

                return myds;

            case POSTGRES:
                PGPoolingDataSource pgds = new PGPoolingDataSource();

                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.");
        }
    }

    protected static List<String> sortStringsList(List<String> list) {
    protected static List<String> sortStringsList(List<String> list) {
        Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
        Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
        return list;
        return list;
@@ -236,11 +203,6 @@ public class TSMUtil {
        return null;
        return null;
    }
    }


//    private static void setTSColumnDescription(Table table, String columnName, String description) {
//        Column column = table.getChild(columnName);
//        column.setDescription(description);
//        column.setStd(true);
//    }
    public static String getNaturalLangueName(TapSchemaEntity entity) {
    public static String getNaturalLangueName(TapSchemaEntity entity) {
        if (entity instanceof Schema) {
        if (entity instanceof Schema) {
            return "schema";
            return "schema";
+22 −7
Original line number Original line Diff line number Diff line
@@ -56,7 +56,6 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
    public static final String KEY_COLUMNS_TABLE = "key_columns";
    public static final String KEY_COLUMNS_TABLE = "key_columns";


    public static final String DESCRIPTION_KEY = "description";
    public static final String DESCRIPTION_KEY = "description";
    public static final String STD_KEY = "std";


    private static final long serialVersionUID = 1678083091602571256L;
    private static final long serialVersionUID = 1678083091602571256L;


@@ -458,7 +457,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {


            // Adding TAP_SCHEMA into TAP_SCHEMA
            // Adding TAP_SCHEMA into TAP_SCHEMA
            addEntireSchema(tapSchemaName);
            addEntireSchema(tapSchemaName);
            fillColumnDescriptionsAndStd(tapSchemaModel, tapSchemaName);
            fillColumnProperties(tapSchemaModel, tapSchemaName);


            if (obscore) {
            if (obscore) {
                SchemaModel ivoaSchemaModel = getIvoaSchemaModel();
                SchemaModel ivoaSchemaModel = getIvoaSchemaModel();
@@ -680,11 +679,22 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        return visibleKeys;
        return visibleKeys;
    }
    }


    private Integer getIntAsBool(Boolean value) {
        if (value == null) {
            return null;
        }
        return value ? 1 : 0;
    }

    /**
    /**
     * Fill descriptions of the TAP_SCHEMA schema entities for a given
     * Fill descriptions of the TAP_SCHEMA schema entities for a given
     * SchemaModel (TAP_SCHEMA or ivoa).
     * SchemaModel (TAP_SCHEMA or ivoa).
     */
     */
    private void fillColumnDescriptionsAndStd(SchemaModel schemaModel, String schemaName) {
    private void fillColumnProperties(SchemaModel schemaModel, String schemaName) {

        // check only on std, but valid also for principal (it depends on TS version)
        boolean useIntegerAsBool = getTapSchemaModel().get(COLUMNS_TABLE).get(Column.STD_KEY).getJavaType() == Integer.class;

        Schema schema = getChild(schemaName);
        Schema schema = getChild(schemaName);
        schema.setValue(DESCRIPTION_KEY, schemaModel.getDescription());
        schema.setValue(DESCRIPTION_KEY, schemaModel.getDescription());
        for (TableModel tableModel : schemaModel.getTables().values()) {
        for (TableModel tableModel : schemaModel.getTables().values()) {
@@ -693,14 +703,19 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
            for (PropertyModel propertyModel : tableModel.getProperties().values()) {
            for (PropertyModel propertyModel : tableModel.getProperties().values()) {
                Column column = table.getChild(propertyModel.getName());
                Column column = table.getChild(propertyModel.getName());
                column.setValue(DESCRIPTION_KEY, propertyModel.getDescription());
                column.setValue(DESCRIPTION_KEY, propertyModel.getDescription());
                if (propertyModel.isStandard()) {
                column.setValue(Column.UCD_KEY, propertyModel.getUcd());
                    column.setValue(STD_KEY, 1);
                column.setValue(Column.UNIT_KEY, propertyModel.getUnit());
                }
                column.setValue(Column.UTYPE_KEY, propertyModel.getUtype());

                Object compatibleStd = useIntegerAsBool ? getIntAsBool(propertyModel.isStandard()) : propertyModel.isStandard();
                Object compatiblePrincipal = useIntegerAsBool ? getIntAsBool(propertyModel.isPrincipal()) : propertyModel.isPrincipal();
                column.setValue(Column.STD_KEY, compatibleStd);
                column.setValue(Column.PRINCIPAL_KEY, compatiblePrincipal);
            }
            }
        }
        }
    }
    }


    private void fillColumnDescriptionsAndStd(SchemaModel schemaModel) {
    private void fillColumnDescriptionsAndStd(SchemaModel schemaModel) {
        fillColumnDescriptionsAndStd(schemaModel, schemaModel.getName());
        fillColumnProperties(schemaModel, schemaModel.getName());
    }
    }
}
}
+20 −22
Original line number Original line Diff line number Diff line
@@ -22,10 +22,8 @@
 */
 */
package it.inaf.ia2.tsm.datalayer;
package it.inaf.ia2.tsm.datalayer;


import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.io.Serializable;
import java.io.Serializable;
import javax.sql.DataSource;
import javax.sql.DataSource;
import org.postgresql.ds.PGPoolingDataSource;


/**
/**
 * Serializable wrapper for a DataSource.
 * Serializable wrapper for a DataSource.
@@ -48,32 +46,32 @@ public class DataSourceWrapper implements Serializable {


    public DataSource getDataSource() {
    public DataSource getDataSource() {
        if (dataSource == null) {
        if (dataSource == null) {
            String driverClassName, url;
            switch (credentials.getDatabaseType()) {
            switch (credentials.getDatabaseType()) {

                case MYSQL:
                case MYSQL:
                    MysqlDataSource myds = new MysqlDataSource();
                    driverClassName = "com.mysql.jdbc.Driver";

                    url = String.format("jdbc:mysql://%s:%s", credentials.getHostname(), credentials.getPort());
                    myds.setServerName(credentials.getHostname());
                    break;
                    myds.setPortNumber(credentials.getPort());
                    myds.setUser(credentials.getUsername());
                    myds.setPassword(credentials.getPassword());

                    return myds;

                case POSTGRES:
                case POSTGRES:
                    PGPoolingDataSource pgds = new PGPoolingDataSource();
                    driverClassName = "org.postgresql.Driver";

                    url = String.format("jdbc:postgresql://%s:%s/%s",
                    pgds.setServerName(credentials.getHostname());
                            credentials.getHostname(), credentials.getPort(), credentials.getDatabase());
                    pgds.setPortNumber(credentials.getPort());
                    break;
                    pgds.setUser(credentials.getUsername());
                    pgds.setPassword(credentials.getPassword());
                    pgds.setDatabaseName(credentials.getDatabase());

                    return pgds;

                default:
                default:
                    throw new UnsupportedOperationException(credentials.getDatabaseType() + " not supported yet.");
                    throw new UnsupportedOperationException(credentials.getDatabaseType() + " not supported yet.");
            }
            }

            org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource();
            ds.setDriverClassName(driverClassName);
            ds.setUrl(url);
            ds.setUsername(credentials.getUsername());
            ds.setPassword(credentials.getPassword());
            ds.setInitialSize(5);
            ds.setMaxActive(10);
            ds.setMaxIdle(5);
            ds.setMinIdle(2);

            dataSource = ds;
        }
        }
        return dataSource;
        return dataSource;
    }
    }
Loading