...
 
Commits (3)
......@@ -87,7 +87,7 @@
<aspectj.version>1.8.9</aspectj.version>
<mysql.version>5.1.46</mysql.version>
<postgres.version>42.2.5</postgres.version>
<hazelcast.version>3.8.1</hazelcast.version>
<oval.version>1.81</oval.version>
......@@ -363,9 +363,9 @@
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgres.version}</version>
</dependency>
<!--Other dependencies -->
......
......@@ -46,13 +46,13 @@ public class DSRow implements EntityId {
private List<DSValue<?>> values;
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(columnDefinition = "binary(16)", updatable = false)
@Column(updatable = false, length=16)
private byte[] md5;
@Column(columnDefinition = "binary(20)", updatable = false)
@Column(updatable = false, length=20)
private byte[] sha1;
@PrePersist
......
......@@ -32,7 +32,7 @@ import javax.persistence.Table;
@DiscriminatorColumn(discriminatorType = DiscriminatorType.INTEGER, name = "typ")
public abstract class DSRowQualifier<T> {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne(fetch=FetchType.LAZY, optional = false)
......
......@@ -20,7 +20,7 @@ import javax.persistence.Table;
@DiscriminatorColumn(discriminatorType = DiscriminatorType.INTEGER, name = "typ")
public abstract class DSValue<T> {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne(fetch=FetchType.LAZY, optional = false)
......
......@@ -40,7 +40,7 @@ public class DimensionKey implements EntityId, Serializable {
private static final long serialVersionUID = 1232115638223004469L;
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(length = 100, nullable = false, updatable = false)
......
......@@ -52,7 +52,7 @@ public class Observation implements EntityId, Serializable {
private static final long serialVersionUID = -7621192124417368090L;
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "`value`")
......
......@@ -32,37 +32,37 @@ public interface Taxonomy2Repository extends JpaRepository<Taxonomy2, Long> {
@Query("select distinct t.genus from Taxonomy2 t where t.genus like ?1")
List<String> autocompleteGenus(String term, Pageable page);
@Query("select distinct t.genus from Taxonomy2 t join t.cropTaxonomies ct where t.genus like ?1 and ct.crop = ?2")
@Query("select distinct t.genus from Taxonomy2 t join t.cropTaxonomies ct where lower(t.genus) like lower(?1) and ct.crop = ?2")
List<String> autocompleteGenusByCrop(String term, Crop crop, Pageable page);
@Query("select distinct t.species from Taxonomy2 t where t.species like ?1)")
@Query("select distinct t.species from Taxonomy2 t where lower(t.species) like lower(?1)")
List<String> autocompleteSpecies(String term, Pageable page);
@Query("select distinct t.species from Taxonomy2 t join t.cropTaxonomies ct where t.species like ?1 and ct.crop = ?2")
@Query("select distinct t.species from Taxonomy2 t join t.cropTaxonomies ct where lower(t.species) like lower(?1) and ct.crop = ?2")
List<String> autocompleteSpeciesByCrop(String term, Crop crop, Pageable page);
@Query("select distinct t.species from Taxonomy2 t where t.species like ?1 and t.genus in (?2)")
@Query("select distinct t.species from Taxonomy2 t where lower(t.species) like lower(?1) and t.genus in (?2)")
List<String> autocompleteSpeciesByGenus(String term, List<String> genus, Pageable page);
@Query("select distinct t.taxonName from Taxonomy2 t where t.taxonName like ?1)")
@Query("select distinct t.taxonName from Taxonomy2 t where lower(t.taxonName) like lower(?1)")
List<String> autocompleteTaxonomy(String term, Pageable page);
@Query("select distinct t.subtaxa from Taxonomy2 t where t.subtaxa like ?1)")
@Query("select distinct t.subtaxa from Taxonomy2 t where lower(t.subtaxa) like lower(?1)")
List<String> autocompleteSubtaxa(String string, Pageable page);
@Query("select distinct t.subtaxa from Taxonomy2 t join t.cropTaxonomies ct where t.subtaxa like ?1 and ct.crop = ?2")
@Query("select distinct t.subtaxa from Taxonomy2 t join t.cropTaxonomies ct where lower(t.subtaxa) like lower(?1) and ct.crop = ?2")
List<String> autocompleteSubtaxaByCrop(String string, Crop crop, Pageable page);
@Query("select distinct t.subtaxa from Taxonomy2 t where t.subtaxa like ?1 and t.genus in (?2)")
@Query("select distinct t.subtaxa from Taxonomy2 t where lower(t.subtaxa) like lower(?1) and t.genus in (?2)")
List<String> autocompleteSubtaxaByGenus(String string, List<String> genus, Pageable page);
@Query("select distinct t.subtaxa from Taxonomy2 t where t.subtaxa like ?1 and t.species in (?2)")
@Query("select distinct t.subtaxa from Taxonomy2 t where lower(t.subtaxa) like lower(?1) and t.species in (?2)")
List<String> autocompleteSubtaxaBySpecies(String string, List<String> species, Pageable page);
@Query("select distinct t.subtaxa from Taxonomy2 t where t.subtaxa like ?1 and t.genus in (?2) and t.species in (?3)")
@Query("select distinct t.subtaxa from Taxonomy2 t where lower(t.subtaxa) like lower(?1) and t.genus in (?2) and t.species in (?3)")
List<String> autocompleteSubtaxaByGenusAndSpecies(String string, List<String> genus, List<String> species, Pageable page);
@Query("select t from Taxonomy2 t where t.genus = ?1 and t.species = ?2 and t.spAuthor = ?3 and t.subtaxa = ?4 and t.subtAuthor = ?5")
@Query("select t from Taxonomy2 t where lower(t.genus) = lower(?1) and lower(t.species) = lower(?2) and lower(t.spAuthor) = lower(?3) and lower(t.subtaxa) = lower(?4) and lower(t.subtAuthor) = lower(?5)")
Taxonomy2 findByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor(String genus, String species, String spAuthor, String subtaxa, String subtAuthor);
List<Taxonomy2> findByGenus(String genus);
......
......@@ -251,8 +251,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
......@@ -277,8 +275,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt);
// Set mysql JConnector to stream results
// stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
......@@ -305,8 +301,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
......@@ -332,8 +326,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
......@@ -346,8 +338,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con
.prepareStatement("select n.accessionId, n.instCode, n.name, n.aliasType, n.lang, n.version, n.id from accession_alias n order by n.accessionId");
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
......@@ -375,8 +365,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
......@@ -390,8 +378,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
final PreparedStatement stmt = con
.prepareStatement("select distinct a.id, a.instCode, a.acceNumb, t.genus from accessiontrait at inner join accession a on a.id=at.accessionId left outer join taxonomy2 t on t.id=a.taxonomyId2 where at.metadataId = ?");
stmt.setLong(1, id);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
......
......@@ -114,8 +114,8 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
return this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
final PreparedStatement pst = conn.prepareStatement("select accessionId, `" + method.getFieldName() + "` as traitvalue from `" + method.getId()
+ "` where metadataId=?");
final PreparedStatement pst = conn.prepareStatement("select accessionId, \"" + method.getFieldName().toLowerCase() + "\" as traitvalue from \"" + method.getId()
+ "\" where metadataId=?");
pst.setLong(1, metadataId);
return pst;
}
......@@ -139,8 +139,8 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
for (final AccessionTrait at : accessionTraits) {
final Method method = methodRepository.findOne(at.getMethodId());
final List<Map<String, Object>> rows = this.jdbcTemplate.queryForList("select metadataId, `" + method.getFieldName() + "` as traitvalue from `"
+ method.getId() + "` where accessionId=?", new Object[] { at.getAccession().getId() });
final List<Map<String, Object>> rows = this.jdbcTemplate.queryForList("select metadataid, \"" + method.getFieldName().toLowerCase() + "\" as traitvalue from \""
+ method.getId() + "\" where accessionId=?", new Object[] { at.getAccession().getId() });
if (rows == null || rows.size() == 0) {
// Skip
......@@ -186,8 +186,8 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
final long methodId = method.getId();
LOG.debug("MethodID={}", methodId);
this.namedJdbcTemplate.query("select accessionId, `" + method.getFieldName() + "` as traitvalue from `" + method.getId()
+ "` where metadataId = :metadataId and accessionId in ( :accessionIds )", paramMap, new RowCallbackHandler() {
this.namedJdbcTemplate.query("select accessionid, \"" + method.getFieldName().toLowerCase() + "\" as traitvalue from \"" + method.getId()
+ "\" where metadataId = :metadataId and accessionId in ( :accessionIds )", paramMap, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
......@@ -216,8 +216,8 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
@Transactional
private void delete(final Metadata metadata, final AccessionId accession, Method method) {
LOG.info("Deleting trait values in methodId={} for metadataId={} and accnId={}", method.getId(), metadata.getId(), accession.getId());
this.jdbcTemplate.update(String.format("DELETE FROM `%s` WHERE accessionId=? AND metadataId=?", method.getId()), new PreparedStatementSetter() {
LOG.info("Deleting trait values in methodid={} for metadataid={} and accnid={}", method.getId(), metadata.getId(), accession.getId());
this.jdbcTemplate.update(String.format("DELETE FROM \"%s\" WHERE accessionid=? AND metadataid=?", method.getId()), new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement pst) throws SQLException {
pst.setLong(1, accession.getId());
......@@ -248,7 +248,7 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
}
this.jdbcTemplate.batchUpdate(
String.format("INSERT INTO `%s` (accessionId, metadataId, `%s`) VALUES (?, ?, ?)", method.getId(), method.getFieldName()),
String.format("INSERT INTO \"%s\" (accessionId, metadataId, \"%s\") VALUES (?, ?, ?)", method.getId(), method.getFieldName().toLowerCase()),
new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement pst, int idx) throws SQLException {
......@@ -342,7 +342,7 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
* @return
*/
private int countTraitAccessions(long methodId, long metadataId) {
return this.jdbcTemplate.queryForObject(String.format("SELECT COUNT(*) FROM `%s` WHERE metadataId=?", methodId), Integer.class, metadataId);
return this.jdbcTemplate.queryForObject(String.format("SELECT COUNT(*) FROM \"%s\" WHERE metadataId=?", methodId), Integer.class, metadataId);
}
/**
......@@ -354,14 +354,14 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
* @return
*/
private int countTraitValues(long methodId, long metadataId, long accessionId) {
return this.jdbcTemplate.queryForObject(String.format("SELECT COUNT(*) FROM `%s` WHERE metadataId=? AND accessionId=?", methodId), Integer.class,
return this.jdbcTemplate.queryForObject(String.format("SELECT COUNT(*) FROM \"%s\" WHERE metadataId=? AND accessionId=?", methodId), Integer.class,
metadataId, accessionId);
}
@Override
public Map<String, Long> getStatistics(Method method) {
final HashMap<String, Long> stats = new HashMap<String, Long>();
this.jdbcTemplate.query(MessageFormat.format("SELECT `{0}`, COUNT(*) FROM `{1,number,#}` GROUP BY `{0}`", method.getFieldName(), method.getId()),
this.jdbcTemplate.query(MessageFormat.format("SELECT \"{0}\", COUNT(*) FROM \"{1,number,#}\" GROUP BY \"{0}\"", method.getFieldName().toLowerCase(), method.getId()),
new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
......
......@@ -51,7 +51,7 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess
@ComponentScan(basePackages= { "org.genesys2.server.security", "org.genesys2.server.service", "org.genesys2.server.component", "org.genesys2.brapi.service", "org.genesys.catalog.service" })
@Import({ HazelcastConfig.class, CommonConfig.class, SchedulerConfig.class, DatabaseConfig.class, TemplatingConfig.class, MailConfig.class, OAuth2ServerConfig.class, SecurityConfig.class, CacheConfig.class,
ElasticsearchConfig.class, FileRepositoryConfig.class, WebSecurityConfig.class, WebConfiguration.class, AuditConfig.class, GLISConfig.class, SwaggerConfig.class, AccessionListenersConfig.class })
ElasticsearchConfig.class, FileRepositoryConfig.class, WebSecurityConfig.class, WebConfiguration.class, AuditConfig.class, GLISConfig.class, SwaggerConfig.class, AccessionListenersConfig.class, ApplicationStartup.class })
@EnableAspectJAutoProxy
@EnableWebSecurity
......
package org.genesys2.spring.config;
import java.util.UUID;
import org.hibernate.dialect.PostgreSQL9Dialect;
import org.hibernate.metamodel.spi.TypeContributions;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.PostgresUUIDType;
public class CustomPostgreSQL9Dialect extends PostgreSQL9Dialect {
private final PostgresUUIDType postgresUUIDType = new PostgresUUIDType() {
private static final long serialVersionUID = 1L;
@Override
public String getName() {
return UUID.class.getName();
}
};
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(typeContributions, serviceRegistry);
typeContributions.contributeType(postgresUUIDType);
}
}
......@@ -49,13 +49,13 @@ build.revision=${buildNumber}
# robots.txt
robots.allow=false
db.url=jdbc:mysql://localhost/genesys?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
db.driverClassName=com.mysql.jdbc.Driver
db.username=root
db.password=
db.url=jdbc:postgresql://localhost:5432/genesys?stringtype=unspecified
db.driverClassName=org.postgresql.Driver
hibernate.dialect=org.genesys2.spring.config.CustomPostgreSQL9Dialect
db.username=genesys
db.password=genesys
db.showSql=false
db.hbm2ddl=false
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
# bit.ly shortener
# TODO change access token and guid
......
......@@ -8,6 +8,9 @@ hibernate.order_updates=true
hibernate.order_inserts=true
hibernate.jdbc.batch_versioned_data=true
# Postgres
hibernate.jdbc.use_streams_for_binary=false
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=false
hibernate.cache.use_minimal_puts=true
......
......@@ -7,16 +7,18 @@ changeLogFile=src/main/resources/liquibase/liquibase-changeLog.yml
#password=
#driver=com.mysql.jdbc.Driver
# Uncomment for mvn liquibase:diff
diffChangeLogFile=src/main/resources/liquibase/liquibase-diff-changeLog.yml
## &hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
# Existing database
url=jdbc:mysql://localhost/genesys20181126?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
username=root
password=
driver=com.mysql.jdbc.Driver
# Upgraded database
referenceUrl=jdbc:mysql://localhost/genesys?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
referenceDriver=com.mysql.jdbc.Driver
referenceUsername=root
referencePassword=
## Uncomment for mvn liquibase:diff
#verbose=true
#logging=debug
#diffChangeLogFile=src/main/resources/liquibase/liquibase-diff-changeLog.yml
## Current database
#url=jdbc:postgresql://localhost:5432/genesys?stringtype=unspecified
#username=mobreza
#password=
#driver=org.postgresql.Driver
## Base database
#referenceUrl=jdbc:postgresql://localhost:5432/genesys2?stringtype=unspecified
#referenceDriver=org.postgresql.Driver
#referenceUsername=mobreza
#referencePassword=
#