Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
07aedce6
Commit
07aedce6
authored
Jul 01, 2013
by
Matija Obreza
Browse files
Removed SparseString
parent
67396eeb
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/crophub/rest/common/model/impl/SparseData.java
View file @
07aedce6
...
...
@@ -18,8 +18,6 @@ package org.crophub.rest.common.model.impl;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.OrderColumn
;
import
javax.persistence.Table
;
...
...
@@ -52,10 +50,6 @@ public class SparseData extends BusinessModel {
@Column
(
nullable
=
false
,
length
=
500
)
private
String
value
;
@ManyToOne
(
cascade
=
{},
optional
=
true
)
@JoinColumn
(
name
=
"stringId"
)
private
SparseString
sparseString
;
public
long
getDatasetId
()
{
return
datasetId
;
...
...
@@ -88,12 +82,4 @@ public class SparseData extends BusinessModel {
public
void
setValue
(
final
String
value
)
{
this
.
value
=
value
;
}
public
SparseString
getSparseString
()
{
return
sparseString
;
}
public
void
setSparseString
(
final
SparseString
sparseString
)
{
this
.
sparseString
=
sparseString
;
}
}
src/main/java/org/crophub/rest/common/model/impl/SparseString.java
deleted
100644 → 0
View file @
67396eeb
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.crophub.rest.common.model.impl
;
import
java.text.MessageFormat
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Table
;
import
org.crophub.rest.common.model.BusinessModel
;
/**
* Strings used in sparse tables
*
* @author mobreza
*/
@Entity
@Table
(
name
=
"sparsestring"
)
public
class
SparseString
extends
BusinessModel
{
private
static
final
long
serialVersionUID
=
5896186555138979311L
;
@Column
private
String
hash
;
@Column
private
int
length
;
@Column
(
length
=
500
,
nullable
=
false
,
updatable
=
false
,
unique
=
true
)
private
String
value
;
public
SparseString
()
{
}
public
SparseString
(
final
String
value
)
{
this
.
value
=
value
;
}
public
int
getHash
()
{
return
this
.
value
.
hashCode
();
}
public
void
setHash
(
final
int
hash
)
{
}
public
int
getLength
()
{
return
this
.
value
.
length
();
}
public
void
setLength
(
final
int
length
)
{
}
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
final
String
value
)
{
this
.
value
=
value
;
}
@Override
public
String
toString
()
{
return
MessageFormat
.
format
(
"String id={0,number,#} value={1}"
,
id
,
value
);
}
}
\ No newline at end of file
src/main/java/org/crophub/rest/common/persistence/domain/SparseStringRepository.java
deleted
100644 → 0
View file @
67396eeb
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.crophub.rest.common.persistence.domain
;
import
java.util.List
;
import
org.crophub.rest.common.model.impl.SparseString
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
public
interface
SparseStringRepository
extends
JpaRepository
<
SparseString
,
Long
>
{
@Query
(
"select ss from SparseString ss where ss.hash=?1 and ss.length=?2 and ss.value=?3"
)
SparseString
find
(
int
hash
,
int
length
,
String
value
);
List
<
SparseString
>
findByHash
(
int
hash
);
/**
* Not really efficient, use {@link #find(int, int, String)}
*
* @param value
* @return
*/
SparseString
findByValue
(
String
value
);
List
<
SparseString
>
findByHashAndLength
(
int
hash
,
int
length
);
}
src/main/java/org/crophub/rest/common/service/SparseStringService.java
deleted
100644 → 0
View file @
67396eeb
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.crophub.rest.common.service
;
import
org.crophub.rest.common.model.impl.SparseString
;
public
interface
SparseStringService
{
SparseString
getString
(
String
string
);
}
src/main/java/org/crophub/rest/common/service/impl/DataServiceImpl.java
View file @
07aedce6
...
...
@@ -17,7 +17,6 @@ import org.crophub.rest.common.persistence.domain.SparseDataRepository;
import
org.crophub.rest.common.persistence.domain.SparseEntryRepository
;
import
org.crophub.rest.common.service.DataService
;
import
org.crophub.rest.common.service.DescriptorService
;
import
org.crophub.rest.common.service.SparseStringService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
...
...
@@ -40,9 +39,6 @@ public class DataServiceImpl implements DataService {
@Autowired
DescriptorService
descriptorService
;
@Autowired
SparseStringService
stringService
;
@Autowired
private
DatasetRepository
datasetRepository
;
...
...
src/main/java/org/crophub/rest/common/service/impl/SparseStringServiceImpl.java
deleted
100644 → 0
View file @
67396eeb
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.crophub.rest.common.service.impl
;
import
org.crophub.rest.common.model.impl.SparseString
;
import
org.crophub.rest.common.persistence.domain.SparseStringRepository
;
import
org.crophub.rest.common.service.SparseStringService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
@Service
@Transactional
(
readOnly
=
true
)
public
class
SparseStringServiceImpl
implements
SparseStringService
{
@Autowired
SparseStringRepository
stringRepository
;
@Override
@Transactional
(
readOnly
=
false
)
@Cacheable
(
value
=
"strings"
,
key
=
"#value"
)
public
SparseString
getString
(
final
String
value
)
{
if
(
value
==
null
)
{
return
null
;
}
SparseString
sparseString
=
stringRepository
.
find
(
value
.
hashCode
(),
value
.
length
(),
value
);
if
(
sparseString
==
null
)
{
sparseString
=
new
SparseString
(
value
);
stringRepository
.
save
(
sparseString
);
}
return
sparseString
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment