public static void main(String[] argv) { // Create and start the engine ... ModeShapeEngine engine = new ModeShapeEngine(); engine.start(); // Load the configuration for a repository via the classloader (can also use path to a file)... Repository repository = null; String repositoryName = null; try { URL url = ModeShapeExample.class.getClassLoader().getResource("my-repository-config.json"); RepositoryConfiguration config = RepositoryConfiguration.read(url); // We could change the name of the repository programmatically ... // config = config.withName("Some Other Repository"); // Verify the configuration for the repository ... Problems problems = config.validate(); if (problems.hasErrors()) { System.err.println("Problems starting the engine."); System.err.println(problems); System.exit(-1); } // Deploy the repository ... repository = engine.deploy(config); repositoryName = config.getName(); } catch (Throwable e) { e.printStackTrace(); System.exit(-1); return; } Session session = null; try { // Get the repository repository = engine.getRepository(repositoryName); // Create a session ... session = repository.login("default"); // Get the root node ... Node root = session.getRootNode(); assert root != null; System.out.println( "Found the root node in the \"" + session.getWorkspace().getName() + "\" workspace"); } catch (RepositoryException e) { e.printStackTrace(); } finally { if (session != null) session.logout(); System.out.println("Shutting down engine ..."); try { engine.shutdown().get(); System.out.println("Success!"); } catch (Exception e) { e.printStackTrace(); } } }
@Override public void start(StartContext arg0) throws StartException { JcrEngine jcr = getEngine(); try { final String repositoryName = repositoryConfiguration.getName(); // Get the index storage configuration ... IndexStorage indexStorageConfig = indexStorageConfigInjector.getValue(); Document queryConfig = null; if (indexStorageConfig != null) { queryConfig = indexStorageConfig.getQueryConfiguration(); } else { // We'll use the default index storage, but this will be overwritten by the *IndexStorageAdd // operation // (that we're dependent upon). The default for non-AS7 ModeShape repositories is to use // RAM index storage, but in AS7 we want to by default store the indexes on the filesystem // in the // AS7 data directory. // We'll do this by setting a path relative to the data directory, and then injecting // the "${jboss.server.data.dir}/modeshape" path into the repository service // (which will then update the configuration prior to deployment) ... EditableDocument query = Schematic.newDocument(); EditableDocument indexing = query.getOrCreateDocument(FieldName.INDEXING); EditableDocument indexStorage = query.getOrCreateDocument(FieldName.INDEX_STORAGE); EditableDocument backend = indexing.getOrCreateDocument(FieldName.INDEXING_BACKEND); query.set(FieldName.REBUILD_UPON_STARTUP, "if_needed"); backend.set(FieldName.TYPE, FieldValue.INDEXING_BACKEND_TYPE_LUCENE); indexStorage.set(FieldName.TYPE, FieldValue.INDEX_STORAGE_FILESYSTEM); String dataDirPath = dataDirectoryPathInjector.getValue(); indexStorage.set( FieldName.INDEX_STORAGE_LOCATION, dataDirPath + "/" + repositoryName + "/indexes"); queryConfig = query; } assert queryConfig != null; // Get the binary storage configuration ... Document binaryConfig = null; BinaryStorage binaryStorageConfig = binaryStorageInjector.getValue(); if (binaryStorageConfig != null) { binaryConfig = binaryStorageConfig.getBinaryConfiguration(); } else { // By default, store the binaries in the data directory ... EditableDocument binaries = Schematic.newDocument(); binaries.set(FieldName.TYPE, FieldValue.BINARY_STORAGE_TYPE_FILE); String dataDirPath = dataDirectoryPathInjector.getValue(); binaries.set(FieldName.DIRECTORY, dataDirPath + "/" + repositoryName + "/binaries"); binaryConfig = binaries; } // Now update the configuration ... Editor editor = repositoryConfiguration.edit(); editor.setDocument(FieldName.QUERY, queryConfig); editor .getOrCreateDocument(FieldName.STORAGE) .setDocument(FieldName.BINARY_STORAGE, binaryConfig); // Apply the changes to the configuration ... editor.apply(editor.getChanges()); // Deploy the repository and use this as the environment ... jcr.deploy(repositoryConfiguration.with(this)); } catch (ConfigurationException e) { throw new StartException(e); } catch (RepositoryException e) { throw new StartException(e); } }
public final String repositoryName() { return repositoryConfiguration.getName(); }