Skip to content

Commit

Permalink
LPS-97450 Inline
Browse files Browse the repository at this point in the history
  • Loading branch information
shuyangzhou authored and brianchandotcom committed Jun 26, 2019
1 parent bcfa68f commit 7bb7be7
Showing 1 changed file with 68 additions and 80 deletions.
Expand Up @@ -74,8 +74,48 @@ public ConfigurationPersistenceManager(
}

@Override
public void delete(final String pid) throws IOException {
doDelete(pid);
public void delete(String pid) throws IOException {
ConfigurationModelListener configurationModelListener = null;

if (!pid.endsWith("factory") && hasPid(pid)) {
Dictionary dictionary = getDictionary(pid);

String pidKey = (String)dictionary.get(
ConfigurationAdmin.SERVICE_FACTORYPID);

if (pidKey == null) {
pidKey = (String)dictionary.get(Constants.SERVICE_PID);
}

if (pidKey == null) {
pidKey = pid;
}

configurationModelListener = _getConfigurationModelListener(pidKey);
}

if (configurationModelListener != null) {
configurationModelListener.onBeforeDelete(pid);
}

Lock lock = _readWriteLock.writeLock();

try {
lock.lock();

Dictionary<?, ?> dictionary = _dictionaries.remove(pid);

if ((dictionary != null) && hasPid(pid)) {
deleteFromDatabase(pid);
}
}
finally {
lock.unlock();
}

if (configurationModelListener != null) {
configurationModelListener.onAfterDelete(pid);
}
}

@Override
Expand Down Expand Up @@ -159,84 +199,6 @@ public void stop() {

@Override
public void store(
final String pid,
@SuppressWarnings("rawtypes") final Dictionary dictionary)
throws IOException {

doStore(pid, dictionary);
}

protected void createConfigurationTable() throws IOException, SQLException {
try (Connection connection = _dataSource.getConnection();
Statement statement = connection.createStatement()) {

statement.executeUpdate(
_db.buildSQL(
"create table Configuration_ (configurationId " +
"VARCHAR(255) not null primary key, dictionary TEXT)"));
}
}

protected void deleteFromDatabase(String pid) throws IOException {
try (Connection connection = _dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(
_db.buildSQL(
"delete from Configuration_ where configurationId = ?"))) {

preparedStatement.setString(1, pid);

preparedStatement.executeUpdate();
}
catch (SQLException sqle) {
throw new IOException(sqle);
}
}

protected void doDelete(String pid) throws IOException {
ConfigurationModelListener configurationModelListener = null;

if (!pid.endsWith("factory") && hasPid(pid)) {
Dictionary dictionary = getDictionary(pid);

String pidKey = (String)dictionary.get(
ConfigurationAdmin.SERVICE_FACTORYPID);

if (pidKey == null) {
pidKey = (String)dictionary.get(Constants.SERVICE_PID);
}

if (pidKey == null) {
pidKey = pid;
}

configurationModelListener = _getConfigurationModelListener(pidKey);
}

if (configurationModelListener != null) {
configurationModelListener.onBeforeDelete(pid);
}

Lock lock = _readWriteLock.writeLock();

try {
lock.lock();

Dictionary<?, ?> dictionary = _dictionaries.remove(pid);

if ((dictionary != null) && hasPid(pid)) {
deleteFromDatabase(pid);
}
}
finally {
lock.unlock();
}

if (configurationModelListener != null) {
configurationModelListener.onAfterDelete(pid);
}
}

protected void doStore(
String pid, @SuppressWarnings("rawtypes") Dictionary dictionary)
throws IOException {

Expand Down Expand Up @@ -292,6 +254,32 @@ protected void doStore(
}
}

protected void createConfigurationTable() throws IOException, SQLException {
try (Connection connection = _dataSource.getConnection();
Statement statement = connection.createStatement()) {

statement.executeUpdate(
_db.buildSQL(
"create table Configuration_ (configurationId " +
"VARCHAR(255) not null primary key, dictionary TEXT)"));
}
}

protected void deleteFromDatabase(String pid) throws IOException {
try (Connection connection = _dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(
_db.buildSQL(
"delete from Configuration_ where configurationId = ?"))) {

preparedStatement.setString(1, pid);

preparedStatement.executeUpdate();
}
catch (SQLException sqle) {
throw new IOException(sqle);
}
}

protected Dictionary<?, ?> getDictionary(String pid) throws IOException {
try (Connection connection = _dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(
Expand Down

0 comments on commit 7bb7be7

Please sign in to comment.