RepoPersistenceManager.java revision 7523c7f44ed55a9882212a3925629e54c1295dae
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright © 2011 ForgeRock AS. All rights reserved.
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*/
// Deprecated
// The ID URI prefix for configuration
// Meta-data when converting from array to list to enable later conversion to original form
private BundleContext ctx;
private JsonResourceObjectSet repo;
//Rapid development may require only memory store.
private final boolean requireRepository = Boolean.valueOf(System.getProperty("openidm.config.repo.enabled", "true"));
// Fall-back is in-memory store of configurations
}
/**
* Handle the system notifying that it's ready to install configs.
*/
public void checkReady() throws BootstrapFailure {
if (requireRepository) {
try {
Filter filter = ctx.createFilter("(" + Constants.OBJECTCLASS + "=" + RepoBootService.class.getName() + ")");
repoTracker.open();
}
}
} catch (InterruptedException ex) {
} catch (InvalidSyntaxException ex) {
} finally {
if (repoTracker != null) {
repoTracker.close();
}
}
throw new BootstrapFailure("Failed to acquire the bootstrap repository service to access configuration persistence.");
}
}
}
try {
checkReady();
} catch (BootstrapFailure e) {
}
}
/**
* Returns <code>true</code> if a persisted <code>Dictionary</code> exists
* for the given <code>pid</code>.
*
* @param pid The identifier for the dictionary to test.
*/
boolean exists = false;
try {
} catch (NotFoundException ex) {
exists = false;
} catch (ObjectSetException ex) {
throw new RuntimeException("Failed to check if configuration exists in repository: " + ex.getMessage(), ex);
}
}
if (!exists) {
if (exists) {
}
} else {
}
if (!exists) {
}
return exists;
}
/**
* Returns the <code>Dictionary</code> for the given <code>pid</code>.
*
* @param pid The identifier for the dictionary to load.
*
* @return The dictionary for the identifier. This must not be
* <code>null</code> but may be empty.
*
* @throws IOException If an error occurrs loading the dictionary. An
* <code>IOException</code> must also be thrown if no dictionary
* exists for the given identifier.
*/
try {
} else if (!requireRepository) {
}
}
} catch (NotFoundException ex) {
}
} catch (ObjectSetException ex) {
}
return result;
}
/**
* Returns an enumeration of all <code>Dictionary</code> objects known to
* this persistence manager.Dictionary
* <p>
* Implementations of this method are allowed to return lazy enumerations.
* That is, it is allowable for the enumeration to not return a dictionary
* if loading it results in an error.
*
* @return A possibly empty Enumeration of all dictionaries.
*
* @throws IOException If an error occurrs getting the dictionaries.
*/
if (isReady(5)) {
} else {
}
return new Enumeration() {
public boolean hasMoreElements() {
boolean hasMore = false;
try {
if (!hasMore) {
List<Map<String, Object>> queryResult = (List<Map<String, Object>>) result.get(QueryConstants.QUERY_RESULT);
}
}
}
} catch (RuntimeException ex) {
logger.warn("Failure getting configuration dictionaries for hasMoreElements " + ex.getMessage(), ex);
throw ex;
logger.warn("Failure getting configuration dictionaries for hasMoreElements " + ex.getMessage(), ex);
throw new RuntimeException(ex);
}
return hasMore;
}
public Object nextElement() {
try {
} else {
}
} catch (RuntimeException ex) {
throw ex;
throw new RuntimeException(ex);
}
}
};
}
/**
* Stores the <code>Dictionary</code> under the given <code>pid</code>.
*
* @param pid The identifier of the dictionary.
* @param properties The <code>Dictionary</code> to store.
*
* @throws IOException If an error occurrs storing the dictionary. If this
* exception is thrown, it is expected, that
* {@link #exists(String) exists(pid} returns <code>false</code>.
*/
// Store config handling settings in memory
return;
}
try {
try {
} catch (NotFoundException ex) {
// Just detect that it doesn't exist
}
boolean retry;
do {
retry = false;
try {
} catch (PreconditionFailedException ex) {
retry = true;
}
} while (retry);
} else {
logger.debug("Existing config same as store request, ignoring {} {} {}", new Object[] {pid, rev, obj});
}
} else {
// This may create a new (empty) configuration, which felix marks with _felix___cm__newConfiguration=true
}
} else {
}
} catch (ObjectSetException ex) {
}
}
/**
* Removes the <code>Dictionary</code> for the given <code>pid</code>. If
* such a dictionary does not exist, this method has no effect.
*
* @param pid The identifier of the dictionary to delet.
*
* @throws IOException If an error occurrs deleting the dictionary. This
* exception must not be thrown if no dictionary with the given
* identifier exists.
*/
}
try {
boolean retry;
do {
retry = false;
try {
}
} catch (PreconditionFailedException ex) {
retry = true;
} catch (NotFoundException ex) {
// If it doesn't exists (anymore) that's fine
}
} while (retry);
}
} catch (ObjectSetException ex) {
throw new IOException("Failed to delete configuration + " + pid + " in repository: " + ex.getMessage(), ex);
}
}
/**
* Convert OSGi pid to an ID suitable for addressing the repository
* @param pid the OSGi pid
* @return the qualified objectset id
*/
return CONFIG_CONTEXT_PREFIX + pid;
}
/**
* Convert dictionary and contents to a Map, compatible with the JSON model.
* Arrays are encoded with special meta-data entries marking their origin as array.
*
* @param dict the (OSGi configuration) dictionary
* @return the converted map
*/
while(keysEnum.hasMoreElements()) {
// Deal with outdated collection classes
if (rawValue instanceof Dictionary) {
// Add marker entries to mark this as coming from an array
}
}
return convert;
}
/**
* Convert the JSON model map and contents to types and contents
* compatible with OSGi configuration Dictionary
* e.g. using legacy types (Hashtables, Vectors),
* Encoded property names decoded.
*
* @param properties map to convert
* @return converted to legacy types
* @throws IOException if the conversion failed
*/
if (properties instanceof Dictionary) {
return (Dictionary) properties;
} else {
}
}
}
try {
logger.warn("Failed to convert back to original array type " + origType + " " + ex.getMessage(), ex);
throw new IOException("Failed to convert back to original array type " + origType + " " + ex.getMessage(), ex);
}
} else {
}
}
}
return converted;
}
}
/*
* Convert to a key (property name) compatible with storing in the repository
*
* Note: does not support keys that contain a sequence of "_.", which should not occur in our configuration files
*/
}
/*
* Convert from encoded version for repository storage to the original key
*/
}
}