Skip to content

Commit

Permalink
[merge] merge of revisions 16954:16957 inclusive from old eXist Subve…
Browse files Browse the repository at this point in the history
…rsion repository (https://exist.svn.sourceforge.net/svnroot/exist/trunk/eXist)

svn path=/trunk/eXist/; revision=16964
  • Loading branch information
adamretter committed Aug 17, 2012
1 parent 4797ee0 commit 7805884
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 41 deletions.
6 changes: 6 additions & 0 deletions collection.xconf.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<collection xmlns="http://exist-db.org/collection-config/1.0">
<triggers>
<trigger class="org.exist.extensions.exquery.restxq.impl.RestXqTrigger"/>
</triggers>
</collection>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import java.util.*;
import org.exist.collections.triggers.FilteringTrigger;
import org.exist.collections.triggers.TriggerException;
import org.exist.dom.BinaryDocument;
import org.exist.dom.DocumentImpl;
import org.exist.dom.DocumentMetadata;
import org.exist.storage.DBBroker;
import org.exist.storage.txn.Txn;
import org.exist.xmldb.XmldbURI;
Expand Down Expand Up @@ -116,14 +118,23 @@ private void deregisterServices(final DBBroker broker, final XmldbURI xqueryLoca
}

private List<RestXqService> findServices(final DBBroker broker, final DocumentImpl document) throws TriggerException {
try {
final CompiledXQuery compiled = XQueryCompiler.compile(broker, document);
return XQueryInspector.findServices(compiled);
} catch(final RestXqServiceCompilationException rxsce) {
throw new TriggerException(rxsce.getMessage(), rxsce);
} catch(final ExQueryException eqe) {
throw new TriggerException(eqe.getMessage(), eqe);

//ensure we have a binary document with the correct mimetype
if(document instanceof BinaryDocument) {
final DocumentMetadata metadata = document.getMetadata();
if(metadata.getMimeType().equals(XQueryCompiler.XQUERY_MIME_TYPE)){
try {
final CompiledXQuery compiled = XQueryCompiler.compile(broker, document);
return XQueryInspector.findServices(compiled);
} catch(final RestXqServiceCompilationException rxsce) {
throw new TriggerException(rxsce.getMessage(), rxsce);
} catch(final ExQueryException eqe) {
throw new TriggerException(eqe.getMessage(), eqe);
}
}
}

return new ArrayList<RestXqService>();
}

private RestXqServiceRegistry getRegistry(final DBBroker broker) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*/
public class XQueryCompiler {

private final static String XQUERY_MIME_TYPE = "application/xquery";
public final static String XQUERY_MIME_TYPE = "application/xquery";

public static CompiledXQuery compile(final DBBroker broker, final URI xqueryLocation) throws RestXqServiceCompilationException {

Expand Down
2 changes: 1 addition & 1 deletion nbproject/private/config.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
config=Jetty
config=InteractiveClient
24 changes: 17 additions & 7 deletions src/org/exist/storage/BrokerPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.exist.collections.Collection;
import org.exist.collections.CollectionCache;
import org.exist.collections.CollectionConfiguration;
import org.exist.collections.CollectionConfigurationException;
import org.exist.collections.CollectionConfigurationManager;
import org.exist.collections.triggers.*;
import org.exist.config.ConfigurationDocumentTrigger;
Expand Down Expand Up @@ -896,12 +897,9 @@ protected void initialize() throws EXistException, DatabaseConfigurationExceptio

statusReporter.setStatus(SIGNAL_READINESS);

//Get a manager to handle further collections configuration
try {
collectionConfigurationManager = new CollectionConfigurationManager(broker);
} catch (Exception e) {
LOG.error("Found an error while initializing database: " + e.getMessage(), e);
}
//Get a manager to handle further collections configuration
initCollectionConfigurationManager(broker);


//wake-up the plugins manager
pluginManager.startUp(broker);
Expand Down Expand Up @@ -1272,9 +1270,21 @@ public TransactionManager getTransactionManager() {
* Returns a manager for accessing the database instance's collection configuration files.
* @return The manager
*/
@Override
public CollectionConfigurationManager getConfigurationManager() {
return collectionConfigurationManager;
}
}

public void initCollectionConfigurationManager(final DBBroker broker) {
if(collectionConfigurationManager == null) {
try {
collectionConfigurationManager = new CollectionConfigurationManager(broker);
} catch(final Exception e) {
LOG.error("Found an error while initializing database: " + e.getMessage(), e);
}
}
}


/**
* Returns a cache in which the database instance's collections are stored.
Expand Down
56 changes: 56 additions & 0 deletions src/org/exist/storage/NativeBroker.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import org.exist.collections.Collection.SubCollectionEntry;
import org.exist.collections.CollectionCache;
import org.exist.collections.CollectionConfiguration;
import org.exist.collections.CollectionConfigurationException;
import org.exist.collections.CollectionConfigurationManager;
import org.exist.collections.triggers.CollectionTriggersVisitor;
import org.exist.collections.triggers.DocumentTriggersVisitor;
import org.exist.collections.triggers.TriggerException;
Expand Down Expand Up @@ -187,6 +189,8 @@ public class NativeBroker extends DBBroker {
public static int OFFSET_COLLECTION_ID = 0;
public static int OFFSET_VALUE = OFFSET_COLLECTION_ID + Collection.LENGTH_COLLECTION_ID; //2

public final static String INIT_COLLECTION_CONFIG = "collection.xconf.init";

/** the database files */
protected CollectionStore collectionsDb;
protected DOMFile domDb;
Expand Down Expand Up @@ -633,6 +637,38 @@ private Collection createTempCollection(Txn transaction)
}
}

private final String readInitCollectionConfig() {
final File fInitCollectionConfig = new File(pool.getConfiguration().getExistHome(), INIT_COLLECTION_CONFIG);
if(fInitCollectionConfig.exists() && fInitCollectionConfig.isFile()) {

InputStream is = null;
try {
final StringBuilder initCollectionConfig = new StringBuilder();

is = new FileInputStream(fInitCollectionConfig);
int read = -1;
byte buf[] = new byte[1024];
while((read = is.read(buf)) != -1) {
initCollectionConfig.append(new String(buf, 0, read));
}

return initCollectionConfig.toString();
} catch(final IOException ioe) {
LOG.error(ioe.getMessage(), ioe);
} finally {
if(is != null) {
try {
is.close();
} catch(final IOException ioe) {
LOG.warn(ioe.getMessage(), ioe);
}
}
}

};
return null;
}

/* (non-Javadoc)
* @see org.exist.storage.DBBroker#getOrCreateCollection(org.exist.storage.txn.Txn, org.exist.xmldb.XmldbURI)
*/
Expand Down Expand Up @@ -663,6 +699,26 @@ public Collection getOrCreateCollection(Txn transaction, XmldbURI name) throws P

//TODO : acquire lock manually if transaction is null ?
saveCollection(transaction, current);


//import an initial collection configuration
try {
final String initCollectionConfig = readInitCollectionConfig();
if(initCollectionConfig != null) {
CollectionConfigurationManager collectionConfigurationManager = pool.getConfigurationManager();
if(collectionConfigurationManager == null) {
//might not yet have been initialised
pool.initCollectionConfigurationManager(this);
collectionConfigurationManager = pool.getConfigurationManager();
}

if(collectionConfigurationManager != null) {
collectionConfigurationManager.addConfiguration(transaction, this, current, initCollectionConfig);
}
}
} catch(final CollectionConfigurationException cce) {
LOG.error("Could not load initial collection configuration for /db: " + cce.getMessage(), cce);
}
}

for(int i=1;i<segments.length;i++) {
Expand Down
47 changes: 22 additions & 25 deletions test/src/org/exist/xquery/XPathQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,33 +153,29 @@ public static void setURI(String collectionURI) {
private Collection testCollection;
private String query;

protected void setUp() {
if (uri.startsWith("xmldb:exist://localhost"))
@Override
protected void setUp() throws Exception {
if (uri.startsWith("xmldb:exist://localhost")) {
initServer();
try {
// initialize driver
Class<?> cl = Class.forName("org.exist.xmldb.DatabaseImpl");
Database database = (Database) cl.newInstance();
database.setProperty("create-database", "true");
DatabaseManager.registerDatabase(database);

Collection root =
DatabaseManager.getCollection(
uri,
"admin",
"");
CollectionManagementService service =
(CollectionManagementService) root.getService(
"CollectionManagementService",
"1.0");
testCollection = service.createCollection("test");
assertNotNull(testCollection);
} catch (ClassNotFoundException e) {
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
} catch (XMLDBException e) {
e.printStackTrace();
}

// initialize driver
Class<?> cl = Class.forName("org.exist.xmldb.DatabaseImpl");
Database database = (Database) cl.newInstance();
database.setProperty("create-database", "true");
DatabaseManager.registerDatabase(database);

Collection root =
DatabaseManager.getCollection(
uri,
"admin",
"");
CollectionManagementService service =
(CollectionManagementService) root.getService(
"CollectionManagementService",
"1.0");
testCollection = service.createCollection("test");
assertNotNull(testCollection);
}

private void initServer() {
Expand All @@ -194,6 +190,7 @@ private void initServer() {
}
}

@Override
protected void tearDown() throws Exception {
try {
TestUtils.cleanupDB();
Expand Down

0 comments on commit 7805884

Please sign in to comment.