use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class RetentionPolicyTest method testSetInvalidRetentionPolicy.
public void testSetInvalidRetentionPolicy() {
try {
RetentionPolicy invalidRPolicy = new RetentionPolicy() {
public String getName() throws RepositoryException {
return "anyName";
}
};
retentionMgr.setRetentionPolicy(testNodePath, invalidRPolicy);
fail("Setting an invalid retention policy must fail.");
} catch (RepositoryException e) {
// success
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class AccessManagerTest method testCanReadNewId.
public void testCanReadNewId() throws Exception {
Session s = getHelper().getReadOnlySession();
try {
NodeImpl n = (NodeImpl) testRootNode.addNode(nodeName1);
PropertyImpl p = (PropertyImpl) n.setProperty(propertyName1, "somevalue");
try {
AccessManager acMgr = getAccessManager(s);
acMgr.canRead(null, n.getId());
fail("expected repositoryexception");
} catch (RepositoryException e) {
// success
}
try {
AccessManager acMgr = getAccessManager(s);
acMgr.canRead(null, p.getId());
fail("expected repositoryexception");
} catch (RepositoryException e) {
// success
}
} finally {
s.logout();
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class CachingDataStore method init.
/**
* Initialized the data store. If the path is not set, <repository
* home>/repository/datastore is used. This directory is automatically
* created if it does not yet exist. During first initialization, it upload
* all files from local datastore to backed and local datastore act as a
* local cache.
*/
@Override
public void init(String homeDir) throws RepositoryException {
try {
if (path == null) {
path = homeDir + "/repository/datastore";
}
// create tmp inside path
tmpDir = new File(path, "tmp");
LOG.info("path=[{}], tmpPath=[{}]", path, tmpDir.getAbsolutePath());
directory = new File(path);
mkdirs(directory);
mkdirs(new File(homeDir));
if (!mkdirs(tmpDir)) {
FileUtils.cleanDirectory(tmpDir);
LOG.info("tmp=[{}] cleaned.", tmpDir.getPath());
}
boolean asyncWriteCacheInitStatus = true;
try {
asyncWriteCache = new AsyncUploadCache();
asyncWriteCache.init(homeDir, path, asyncUploadLimit);
} catch (Exception e) {
LOG.warn("Failed to initialize asyncWriteCache", e);
asyncWriteCacheInitStatus = false;
}
backend = createBackend();
backend.init(this, path, config);
String markerFileName = getMarkerFile();
if (markerFileName != null && !"".equals(markerFileName.trim())) {
// create marker file in homeDir to avoid deletion in cache
// cleanup.
File markerFile = new File(homeDir, markerFileName);
if (!markerFile.exists()) {
LOG.info("load files from local cache");
uploadFilesFromCache();
try {
markerFile.createNewFile();
} catch (IOException e) {
throw new DataStoreException("Could not create marker file " + markerFile.getAbsolutePath(), e);
}
} else {
LOG.info("marker file = [{}] exists ", markerFile.getAbsolutePath());
if (!asyncWriteCacheInitStatus) {
LOG.info("Initialization of asyncWriteCache failed. " + "Re-loading all files from local cache");
uploadFilesFromCache();
asyncWriteCache.reset();
}
}
} else {
throw new DataStoreException("Failed to intialized DataStore." + " MarkerFileName is null or empty. ");
}
// upload any leftover async uploads to backend during last shutdown
Set<String> fileList = asyncWriteCache.getAll();
if (fileList != null && !fileList.isEmpty()) {
List<String> errorFiles = new ArrayList<String>();
LOG.info("Uploading [{}] and size=[{}] from AsyncUploadCache.", fileList, fileList.size());
long totalSize = 0;
List<File> files = new ArrayList<File>(fileList.size());
for (String fileName : fileList) {
File f = new File(path, fileName);
if (!f.exists()) {
errorFiles.add(fileName);
LOG.error("Cannot upload pending file [{}]. File doesn't exist.", f.getAbsolutePath());
} else {
totalSize += f.length();
files.add(new File(path, fileName));
}
}
new FilesUploader(files, totalSize, concurrentUploadsThreads, true).upload();
if (!continueOnAsyncUploadFailure && errorFiles.size() > 0) {
LOG.error("Pending uploads of files [{}] failed. Files do not exist in Local cache.", errorFiles);
LOG.error("To continue set [continueOnAsyncUploadFailure] " + "to true in Datastore configuration in " + "repository.xml. There would be inconsistent data " + "in repository due the missing files. ");
throw new RepositoryException("Cannot upload async uploads from local cache. Files not found.");
} else {
if (errorFiles.size() > 0) {
LOG.error("Pending uploads of files [{}] failed. Files do" + " not exist in Local cache. Continuing as " + "[continueOnAsyncUploadFailure] is set to true.", errorFiles);
}
LOG.info("Reseting AsyncWrite Cache list.");
asyncWriteCache.reset();
}
}
downloadExecService = Executors.newFixedThreadPool(5, new NamedThreadFactory("backend-file-download-worker"));
cache = new LocalCache(path, tmpDir.getAbsolutePath(), cacheSize, cachePurgeTrigFactor, cachePurgeResizeFactor, asyncWriteCache);
/*
* Initialize LRU cache of size {@link #recLengthCacheSize}
*/
recLenCache = Collections.synchronizedMap(new LinkedHashMap<DataIdentifier, Long>(recLengthCacheSize, 0.75f, true) {
private static final long serialVersionUID = -8752749075395630485L;
@Override
protected boolean removeEldestEntry(Map.Entry<DataIdentifier, Long> eldest) {
if (size() > recLengthCacheSize) {
LOG.trace("evicted from recLengthCache [{}]", eldest.getKey());
return true;
}
return false;
}
});
} catch (Exception e) {
throw new RepositoryException(e);
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class DbDataStore method initDatabaseType.
protected void initDatabaseType() throws DataStoreException {
boolean failIfNotFound = false;
if (databaseType == null) {
if (dataSourceName != null) {
try {
databaseType = connectionFactory.getDataBaseType(dataSourceName);
} catch (RepositoryException e) {
throw new DataStoreException(e);
}
} else {
if (!url.startsWith("jdbc:")) {
return;
}
int start = "jdbc:".length();
int end = url.indexOf(':', start);
databaseType = url.substring(start, end);
}
} else {
failIfNotFound = true;
}
InputStream in = DbDataStore.class.getResourceAsStream(databaseType + ".properties");
if (in == null) {
if (failIfNotFound) {
String msg = "Configuration error: The resource '" + databaseType + ".properties' could not be found;" + " Please verify the databaseType property";
log.debug(msg);
throw new DataStoreException(msg);
} else {
return;
}
}
Properties prop = new Properties();
try {
try {
prop.load(in);
} finally {
in.close();
}
} catch (IOException e) {
String msg = "Configuration error: Could not read properties '" + databaseType + ".properties'";
log.debug(msg);
throw new DataStoreException(msg, e);
}
if (driver == null) {
driver = getProperty(prop, "driver", driver);
}
tableSQL = getProperty(prop, "table", tableSQL);
createTableSQL = getProperty(prop, "createTable", createTableSQL);
insertTempSQL = getProperty(prop, "insertTemp", insertTempSQL);
updateDataSQL = getProperty(prop, "updateData", updateDataSQL);
updateLastModifiedSQL = getProperty(prop, "updateLastModified", updateLastModifiedSQL);
updateSQL = getProperty(prop, "update", updateSQL);
deleteSQL = getProperty(prop, "delete", deleteSQL);
deleteOlderSQL = getProperty(prop, "deleteOlder", deleteOlderSQL);
selectMetaSQL = getProperty(prop, "selectMeta", selectMetaSQL);
selectAllSQL = getProperty(prop, "selectAll", selectAllSQL);
selectDataSQL = getProperty(prop, "selectData", selectDataSQL);
storeStream = getProperty(prop, "storeStream", storeStream);
if (!STORE_SIZE_MINUS_ONE.equals(storeStream) && !STORE_TEMP_FILE.equals(storeStream) && !STORE_SIZE_MAX.equals(storeStream)) {
String msg = "Unsupported Stream store mechanism: " + storeStream + " supported are: " + STORE_SIZE_MINUS_ONE + ", " + STORE_TEMP_FILE + ", " + STORE_SIZE_MAX;
log.debug(msg);
throw new DataStoreException(msg);
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class ExportDocViewTest method readDocument.
/**
* Reads a DOM document from the given XML stream.
*
* @param xml XML stream
* @return DOM document
* @throws RepositoryException if the document could not be read
*/
private Document readDocument(InputStream xml) throws RepositoryException {
try {
StreamSource source = new StreamSource(xml);
DOMResult result = new DOMResult();
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.transform(source, result);
return (Document) result.getNode();
} catch (TransformerException e) {
throw new RepositoryException("Unable to read xml file", e);
}
}
Aggregations