macaw.persistenceLayer.production
Class SQLValueLabelManager
java.lang.Object
macaw.persistenceLayer.production.SQLCurationConceptManager
macaw.persistenceLayer.production.SQLValueLabelManager
public class SQLValueLabelManager
- extends SQLCurationConceptManager
Copyright 2010 Medical Research Council Unit for Lifelong Health and Ageing
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.
- Version:
- 1.0
- Author:
- Kevin Garwood (kgarwood@users.sourceforge.net)
Method Summary |
void |
addValueLabels(java.sql.Connection connection,
User user,
Variable variable,
java.util.ArrayList<ValueLabel> valueLabels)
|
void |
checkValueLabelExists(java.sql.Connection connection,
ValueLabel candidateValueLabel)
public void checkValueLabelDuplicate(Connection connection,
Variable variable,
ValueLabel candidateValueLabel) throws MacawException {
StringBuilder query = new StringBuilder();
query.append("SELECT identifier ");
query.append("FROM value_labels ");
query.append("WHERE variable_id=? AND (value=? OR label=?);");
//TO DO
ResultSet resultSet = null;
PreparedStatement statement = null;
try {
statement
= connection.prepareStatement(query.toString());
statement.setInt(1, variable.getIdentifier());
statement.setString(2, candidateValueLabel.getValue());
statement.setString(3, candidateValueLabel.getLabel());
resultSet = statement.executeQuery();
if (resultSet.next() == true) {
int resultIdentifier = resultSet.getInt(1);
if (resultIdentifier != candidateValueLabel.getIdentifier()) {
//items have same display name but different IDs. |
void |
clear(java.sql.Connection connection)
|
void |
createTable(java.sql.Connection connection)
|
void |
deleteValueLabels(java.sql.Connection connection,
User user,
Variable variable,
java.util.ArrayList<ValueLabel> valueLabels)
|
ValueLabel |
getOriginalValueLabel(java.sql.Connection connection,
ValueLabel targetValueLabel)
|
int |
getValueLabelIdentifier(java.sql.Connection connection,
Variable variable,
ValueLabel candidateValueLabel)
|
java.util.ArrayList<ValueLabel> |
getValueLabels(java.sql.Connection connection,
User user,
java.lang.String variableName)
|
java.util.ArrayList<ValueLabel> |
getValueLabels(java.sql.Connection connection,
User user,
Variable variable)
|
void |
updateValueLabels(java.sql.Connection connection,
User user,
Variable variable,
java.util.ArrayList<ValueLabel> revisedValueLabels)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SQLValueLabelManager
public SQLValueLabelManager(SQLChangeEventManager changeEventManager)
createTable
public void createTable(java.sql.Connection connection)
throws MacawException
- Throws:
MacawException
getValueLabels
public java.util.ArrayList<ValueLabel> getValueLabels(java.sql.Connection connection,
User user,
java.lang.String variableName)
throws MacawException
- Throws:
MacawException
getValueLabels
public java.util.ArrayList<ValueLabel> getValueLabels(java.sql.Connection connection,
User user,
Variable variable)
throws MacawException
- Throws:
MacawException
addValueLabels
public void addValueLabels(java.sql.Connection connection,
User user,
Variable variable,
java.util.ArrayList<ValueLabel> valueLabels)
throws MacawException
- Throws:
MacawException
updateValueLabels
public void updateValueLabels(java.sql.Connection connection,
User user,
Variable variable,
java.util.ArrayList<ValueLabel> revisedValueLabels)
throws MacawException
- Throws:
MacawException
deleteValueLabels
public void deleteValueLabels(java.sql.Connection connection,
User user,
Variable variable,
java.util.ArrayList<ValueLabel> valueLabels)
throws MacawException
- Throws:
MacawException
getOriginalValueLabel
public ValueLabel getOriginalValueLabel(java.sql.Connection connection,
ValueLabel targetValueLabel)
throws MacawException
- Throws:
MacawException
getValueLabelIdentifier
public int getValueLabelIdentifier(java.sql.Connection connection,
Variable variable,
ValueLabel candidateValueLabel)
throws MacawException
- Throws:
MacawException
clear
public void clear(java.sql.Connection connection)
throws MacawException
- Throws:
MacawException
checkValueLabelExists
public void checkValueLabelExists(java.sql.Connection connection,
ValueLabel candidateValueLabel)
throws MacawException
- public void checkValueLabelDuplicate(Connection connection,
Variable variable,
ValueLabel candidateValueLabel) throws MacawException {
StringBuilder query = new StringBuilder();
query.append("SELECT identifier ");
query.append("FROM value_labels ");
query.append("WHERE variable_id=? AND (value=? OR label=?);");
//TO DO
ResultSet resultSet = null;
PreparedStatement statement = null;
try {
statement
= connection.prepareStatement(query.toString());
statement.setInt(1, variable.getIdentifier());
statement.setString(2, candidateValueLabel.getValue());
statement.setString(3, candidateValueLabel.getLabel());
resultSet = statement.executeQuery();
if (resultSet.next() == true) {
int resultIdentifier = resultSet.getInt(1);
if (resultIdentifier != candidateValueLabel.getIdentifier()) {
//items have same display name but different IDs. Therefore
//the candidate is a duplicate
String errorMessage
= MacawMessages.getMessage("valueLabel.error.duplicateExists",
candidateValueLabel.getDisplayName());
MacawException exception
= new MacawException(MacawErrorType.DUPLICATE_VALUE_LABEL,
errorMessage);
throw exception;
}
}
}
catch(SQLException exception) {
String errorMessage
= MacawMessages.getMessage("sql.error.unableToCheckValueLabelDuplicates");
MacawException macawException
= new MacawException(MacawErrorType.UNABLE_TO_CHECK_VALUE_LABEL_DUPLICATES,
errorMessage);
throw macawException;
}
finally {
try {
if (resultSet != null) {
resultSet.close();
}
if (statement != null) {
statement.close();
}
}
catch(SQLException exception) {
String errorMessage
= MacawMessages.getMessage("sql.error.unableToCloseConnection");
MacawException macawException
= new MacawException(MacawErrorType.UNABLE_TO_CLOSE_CONNECTION,
errorMessage);
throw macawException;
}
}
}
- Throws:
MacawException