Commit 6ead4194 authored by Matija Obreza's avatar Matija Obreza

Update models and repositories for Postgres

parent 4c4c9a28
...@@ -46,13 +46,13 @@ public class DSRow implements EntityId { ...@@ -46,13 +46,13 @@ public class DSRow implements EntityId {
private List<DSValue<?>> values; private List<DSValue<?>> values;
@Id @Id
@GeneratedValue(strategy = GenerationType.TABLE) @GeneratedValue(strategy = GenerationType.AUTO)
private Long id; private Long id;
@Column(columnDefinition = "binary(16)", updatable = false) @Column(updatable = false, length=16)
private byte[] md5; private byte[] md5;
@Column(columnDefinition = "binary(20)", updatable = false) @Column(updatable = false, length=20)
private byte[] sha1; private byte[] sha1;
@PrePersist @PrePersist
......
...@@ -32,7 +32,7 @@ import javax.persistence.Table; ...@@ -32,7 +32,7 @@ import javax.persistence.Table;
@DiscriminatorColumn(discriminatorType = DiscriminatorType.INTEGER, name = "typ") @DiscriminatorColumn(discriminatorType = DiscriminatorType.INTEGER, name = "typ")
public abstract class DSRowQualifier<T> { public abstract class DSRowQualifier<T> {
@Id @Id
@GeneratedValue(strategy = GenerationType.TABLE) @GeneratedValue(strategy = GenerationType.AUTO)
private Long id; private Long id;
@ManyToOne(fetch=FetchType.LAZY, optional = false) @ManyToOne(fetch=FetchType.LAZY, optional = false)
......
...@@ -20,7 +20,7 @@ import javax.persistence.Table; ...@@ -20,7 +20,7 @@ import javax.persistence.Table;
@DiscriminatorColumn(discriminatorType = DiscriminatorType.INTEGER, name = "typ") @DiscriminatorColumn(discriminatorType = DiscriminatorType.INTEGER, name = "typ")
public abstract class DSValue<T> { public abstract class DSValue<T> {
@Id @Id
@GeneratedValue(strategy = GenerationType.TABLE) @GeneratedValue(strategy = GenerationType.AUTO)
private Long id; private Long id;
@ManyToOne(fetch=FetchType.LAZY, optional = false) @ManyToOne(fetch=FetchType.LAZY, optional = false)
......
...@@ -40,7 +40,7 @@ public class DimensionKey implements EntityId, Serializable { ...@@ -40,7 +40,7 @@ public class DimensionKey implements EntityId, Serializable {
private static final long serialVersionUID = 1232115638223004469L; private static final long serialVersionUID = 1232115638223004469L;
@Id @Id
@GeneratedValue(strategy = GenerationType.TABLE) @GeneratedValue(strategy = GenerationType.AUTO)
private Long id; private Long id;
@Column(length = 100, nullable = false, updatable = false) @Column(length = 100, nullable = false, updatable = false)
......
...@@ -52,7 +52,7 @@ public class Observation implements EntityId, Serializable { ...@@ -52,7 +52,7 @@ public class Observation implements EntityId, Serializable {
private static final long serialVersionUID = -7621192124417368090L; private static final long serialVersionUID = -7621192124417368090L;
@Id @Id
@GeneratedValue(strategy = GenerationType.TABLE) @GeneratedValue(strategy = GenerationType.AUTO)
private Long id; private Long id;
@Column(name = "`value`") @Column(name = "`value`")
......
...@@ -32,37 +32,37 @@ public interface Taxonomy2Repository extends JpaRepository<Taxonomy2, Long> { ...@@ -32,37 +32,37 @@ public interface Taxonomy2Repository extends JpaRepository<Taxonomy2, Long> {
@Query("select distinct t.genus from Taxonomy2 t where t.genus like ?1") @Query("select distinct t.genus from Taxonomy2 t where t.genus like ?1")
List<String> autocompleteGenus(String term, Pageable page); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); Taxonomy2 findByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor(String genus, String species, String spAuthor, String subtaxa, String subtAuthor);
List<Taxonomy2> findByGenus(String genus); List<Taxonomy2> findByGenus(String genus);
......
...@@ -251,8 +251,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos ...@@ -251,8 +251,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters()); final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt); apss.setValues(stmt);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt; return stmt;
} }
}, rowCallbackHandler); }, rowCallbackHandler);
...@@ -277,8 +275,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos ...@@ -277,8 +275,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters()); final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt); apss.setValues(stmt);
// Set mysql JConnector to stream results
// stmt.setFetchSize(Integer.MIN_VALUE);
return stmt; return stmt;
} }
}, rowCallbackHandler); }, rowCallbackHandler);
...@@ -305,8 +301,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos ...@@ -305,8 +301,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters()); final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt); apss.setValues(stmt);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt; return stmt;
} }
}, rowCallbackHandler); }, rowCallbackHandler);
...@@ -332,8 +326,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos ...@@ -332,8 +326,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters()); final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt); apss.setValues(stmt);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt; return stmt;
} }
}, rowCallbackHandler); }, rowCallbackHandler);
...@@ -346,8 +338,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos ...@@ -346,8 +338,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException { public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con 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"); .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; return stmt;
} }
}, rowCallbackHandler); }, rowCallbackHandler);
...@@ -375,8 +365,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos ...@@ -375,8 +365,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters()); final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt); apss.setValues(stmt);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt; return stmt;
} }
}, rowCallbackHandler); }, rowCallbackHandler);
...@@ -390,8 +378,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos ...@@ -390,8 +378,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
final PreparedStatement stmt = con 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 = ?"); .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); stmt.setLong(1, id);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt; return stmt;
} }
}, rowCallbackHandler); }, rowCallbackHandler);
......
...@@ -114,8 +114,8 @@ public class TraitValueRepositoryImpl implements TraitValueRepository { ...@@ -114,8 +114,8 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
return this.jdbcTemplate.query(new PreparedStatementCreator() { return this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override @Override
public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
final PreparedStatement pst = conn.prepareStatement("select accessionId, `" + method.getFieldName() + "` as traitvalue from `" + method.getId() final PreparedStatement pst = conn.prepareStatement("select accessionId, \"" + method.getFieldName().toLowerCase() + "\" as traitvalue from \"" + method.getId()
+ "` where metadataId=?"); + "\" where metadataId=?");
pst.setLong(1, metadataId); pst.setLong(1, metadataId);
return pst; return pst;
} }
...@@ -139,8 +139,8 @@ public class TraitValueRepositoryImpl implements TraitValueRepository { ...@@ -139,8 +139,8 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
for (final AccessionTrait at : accessionTraits) { for (final AccessionTrait at : accessionTraits) {
final Method method = methodRepository.findOne(at.getMethodId()); final Method method = methodRepository.findOne(at.getMethodId());
final List<Map<String, Object>> rows = this.jdbcTemplate.queryForList("select metadataId, `" + method.getFieldName() + "` as traitvalue from `" 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() }); + method.getId() + "\" where accessionId=?", new Object[] { at.getAccession().getId() });
if (rows == null || rows.size() == 0) { if (rows == null || rows.size() == 0) {
// Skip // Skip
...@@ -186,8 +186,8 @@ public class TraitValueRepositoryImpl implements TraitValueRepository { ...@@ -186,8 +186,8 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
final long methodId = method.getId(); final long methodId = method.getId();
LOG.debug("MethodID={}", methodId); LOG.debug("MethodID={}", methodId);
this.namedJdbcTemplate.query("select accessionId, `" + method.getFieldName() + "` as traitvalue from `" + method.getId() this.namedJdbcTemplate.query("select accessionid, \"" + method.getFieldName().toLowerCase() + "\" as traitvalue from \"" + method.getId()
+ "` where metadataId = :metadataId and accessionId in ( :accessionIds )", paramMap, new RowCallbackHandler() { + "\" where metadataId = :metadataId and accessionId in ( :accessionIds )", paramMap, new RowCallbackHandler() {
@Override @Override
public void processRow(ResultSet rs) throws SQLException { public void processRow(ResultSet rs) throws SQLException {
...@@ -216,8 +216,8 @@ public class TraitValueRepositoryImpl implements TraitValueRepository { ...@@ -216,8 +216,8 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
@Transactional @Transactional
private void delete(final Metadata metadata, final AccessionId accession, Method method) { 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()); 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() { this.jdbcTemplate.update(String.format("DELETE FROM \"%s\" WHERE accessionid=? AND metadataid=?", method.getId()), new PreparedStatementSetter() {
@Override @Override
public void setValues(PreparedStatement pst) throws SQLException { public void setValues(PreparedStatement pst) throws SQLException {
pst.setLong(1, accession.getId()); pst.setLong(1, accession.getId());
...@@ -248,7 +248,7 @@ public class TraitValueRepositoryImpl implements TraitValueRepository { ...@@ -248,7 +248,7 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
} }
this.jdbcTemplate.batchUpdate( 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() { new BatchPreparedStatementSetter() {
@Override @Override
public void setValues(PreparedStatement pst, int idx) throws SQLException { public void setValues(PreparedStatement pst, int idx) throws SQLException {
...@@ -342,7 +342,7 @@ public class TraitValueRepositoryImpl implements TraitValueRepository { ...@@ -342,7 +342,7 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
* @return * @return
*/ */
private int countTraitAccessions(long methodId, long metadataId) { 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 { ...@@ -354,14 +354,14 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
* @return * @return
*/ */
private int countTraitValues(long methodId, long metadataId, long accessionId) { 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); metadataId, accessionId);
} }
@Override @Override
public Map<String, Long> getStatistics(Method method) { public Map<String, Long> getStatistics(Method method) {
final HashMap<String, Long> stats = new HashMap<String, Long>(); 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() { new RowCallbackHandler() {
@Override @Override
public void processRow(ResultSet rs) throws SQLException { public void processRow(ResultSet rs) throws SQLException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment