There is no need to schutdown the repo. That is probably why you get the close 
of the connection. I use the following code that verifies if the custom node 
types are by looking for a custom node type. If not, it load the custom node 
types

    public Session getSession(HttpServletRequest request, Repository repository,
        String workspace)
        throws LoginException, RepositoryException, ServletException {
        Session session = super.getSession(request, repository, workspace);
        attachCustomNodeTypes(session);
        return session;
    }

    public void attachCustomNodeTypes(Session session) throws 
RepositoryException {
        try {
            // create 'custom' namespace if necessary
            Workspace workspace = session.getWorkspace();
            NamespaceRegistry reg = workspace.getNamespaceRegistry();
            String[] prefixes = reg.getPrefixes();
            JackrabbitNodeTypeManager manager = (JackrabbitNodeTypeManager) 
session.getWorkspace().getNodeTypeManager();

            if (!manager.hasNodeType(JCR_FOLDER)) { // Check if the Ogle schema 
is loaded
                NamespaceRegistry nsReg = workspace.getNamespaceRegistry();
                nsReg.registerNamespace("ogle", "http://www.ogle.nl/ogle";);

                // Register the custom node types defined in the CND file
                InputStream is = 
Thread.currentThread().getContextClassLoader().getResourceAsStream("custom.cnd");
                manager.registerNodeTypes(is, 
JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
            }

        } catch (IOException ex) {
            throw new RepositoryException(ex.getMessage());
        }
    }

On 18 mei 2010, at 10:26, Daniele Cherchi wrote:

> Hi all, I have a problem. I use the following lines to add a new type node 
> into jackrabbit:
> 
> NodeTypeManagerImpl manager = (NodeTypeManagerImpl) 
> session.getWorkspace().getNodeTypeManager();
> manager.registerNodeTypes( new FileInputStream(pathFile), 
> NodeTypeManagerImpl.TEXT_X_JCR_CND);
> session.save();  getRepositoryImpl().shutdown();
> 
> NOTE: with or without session.save is the same
> 
> Wher I run my application, I get this log:
> 
> 2010-05-18 10:14:53,265  INFO (org.apache.jackrabbit.core.RepositoryImpl:304) 
> - Starting repository...
> 2010-05-18 09:53:22,281 ERROR 
> (org.apache.jackrabbit.core.util.db.DbUtility:92) - failed to close Statement
> 2010-05-18 09:53:22,281 ERROR 
> (org.apache.jackrabbit.core.util.db.DbUtility:94) -        Reason: Already 
> closed
> 2010-05-18 09:53:22,281 ERROR 
> (org.apache.jackrabbit.core.util.db.DbUtility:95) -    State/Code: null/0
> 2010-05-18 09:53:22,281 ERROR 
> (org.apache.jackrabbit.core.util.db.DbUtility:92) - failed to close Connection
> 2010-05-18 09:53:22,296 ERROR 
> (org.apache.jackrabbit.core.util.db.DbUtility:94) -        Reason: Connection 
> is closed.
> 2010-05-18 09:53:22,296 ERROR 
> (org.apache.jackrabbit.core.util.db.DbUtility:95) -    State/Code: null/0
> 2010-05-18 10:14:53,531  INFO 
> (org.apache.jackrabbit.core.fs.local.LocalFileSystem:164) - LocalFileSystem 
> initialized at path XXXXXX\testRepo\version
> 2010-05-18 10:14:53,562  INFO 
> (org.apache.jackrabbit.core.persistence.db.DatabasePersistenceManager:218) - 
> Database: MySQL / 5.1.42-enterprise-gpl-pro
> 2010-05-18 10:14:53,562  INFO 
> (org.apache.jackrabbit.core.persistence.db.DatabasePersistenceManager:219) - 
> Driver: MySQL-AB JDBC Driver / mysql-connector-java-5.1.10 ( Revision: 
> ${svn.Revision} )
> 2010-05-18 10:14:53,625  INFO 
> (org.apache.jackrabbit.core.RepositoryImpl:1996) - initializing workspace 
> 'test'...
> 2010-05-18 10:14:53,640  INFO 
> (org.apache.jackrabbit.core.persistence.db.DatabasePersistenceManager:218) - 
> Database: MySQL / 5.1.42-enterprise-gpl-pro
> 2010-05-18 10:14:53,640  INFO 
> (org.apache.jackrabbit.core.persistence.db.DatabasePersistenceManager:219) - 
> Driver: MySQL-AB JDBC Driver / mysql-connector-java-5.1.10 ( Revision: 
> ${svn.Revision} )
> 
> 
> Why there are these errors in close Statement and close connection, when my 
> application starts?
> 
> This error only occurs when add new typecode.
> 
> Thanks
> Daniele

Reply via email to