From commits-return-18491-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Thu Jun 05 18:58:35 2008 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 72034 invoked from network); 5 Jun 2008 18:58:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Jun 2008 18:58:34 -0000 Received: (qmail 13253 invoked by uid 500); 5 Jun 2008 18:58:37 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 13216 invoked by uid 500); 5 Jun 2008 18:58:37 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 13207 invoked by uid 99); 5 Jun 2008 18:58:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jun 2008 11:58:37 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jun 2008 18:57:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9D02623889FF; Thu, 5 Jun 2008 11:58:13 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r663698 - in /directory/studio/trunk: ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ ldapbrowser-core/src/main/java/org/apache/d... Date: Thu, 05 Jun 2008 18:58:13 -0000 To: commits@directory.apache.org From: seelmann@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080605185813.9D02623889FF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: seelmann Date: Thu Jun 5 11:58:13 2008 New Revision: 663698 URL: http://svn.apache.org/viewvc?rev=663698&view=rev Log: First fix for DIRSTUDIO-326: o Changed the way how the schema is loaded o Schema caching did not work Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/properties/SchemaPropertyPage.java Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java?rev=663698&r1=663697&r2=663698&view=diff ============================================================================== --- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java (original) +++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java Thu Jun 5 11:58:13 2008 @@ -25,7 +25,6 @@ import java.util.Collection; import java.util.List; -import org.apache.directory.shared.ldap.name.LdapDN; import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.IConnectionListener; @@ -34,15 +33,8 @@ import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeAttributesJob; import org.apache.directory.studio.ldapbrowser.core.jobs.ReloadSchemasJob; -import org.apache.directory.studio.ldapbrowser.core.jobs.SearchJob; -import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE; -import org.apache.directory.studio.ldapbrowser.core.model.ISearch; -import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; -import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter; -import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope; -import org.apache.directory.studio.ldapbrowser.core.model.impl.Search; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; @@ -79,6 +71,9 @@ BrowserConnectionUpdateEvent browserConnectionUpdateEvent = new BrowserConnectionUpdateEvent( browserConnection, BrowserConnectionUpdateEvent.Detail.BROWSER_CONNECTION_OPENED ); EventRegistry.fireBrowserConnectionUpdated( browserConnectionUpdateEvent, this ); + BrowserConnectionUpdateEvent schemaUpdateEvent = new BrowserConnectionUpdateEvent( browserConnection, + BrowserConnectionUpdateEvent.Detail.SCHEMA_UPDATED ); + EventRegistry.fireBrowserConnectionUpdated( schemaUpdateEvent, this ); } } } @@ -117,78 +112,10 @@ */ private static void openBrowserConnection( IBrowserConnection browserConnection, StudioProgressMonitor monitor ) { + ReloadSchemasJob.reloadSchema( false, browserConnection, monitor ); + IRootDSE rootDSE = browserConnection.getRootDSE(); InitializeAttributesJob.initializeAttributes( rootDSE, true, monitor ); - - // check schema reload - if ( rootDSE != null ) - { - try - { - monitor.reportProgress( BrowserCoreMessages.model__loading_schema ); - - // check if schema is cached - Schema schema = browserConnection.getSchema(); - if ( schema == Schema.DEFAULT_SCHEMA ) - { - ReloadSchemasJob.reloadSchema( browserConnection, monitor ); - } - else if ( rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) != null ) - { - // check if schema is up-to-date - SearchParameter sp = new SearchParameter(); - sp.setSearchBase( new LdapDN( rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) - .getStringValue() ) ); - sp.setFilter( Schema.SCHEMA_FILTER ); - sp.setScope( SearchScope.OBJECT ); - sp.setReturningAttributes( new String[] - { IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP, - IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP, } ); - ISearch search = new Search( browserConnection, sp ); - - SearchJob.searchAndUpdateModel( browserConnection, search, monitor ); - ISearchResult[] results = search.getSearchResults(); - - if ( results != null && results.length == 1 ) - { - String schemaTimestamp = results[0] - .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ) != null ? results[0] - .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ).getStringValue() : null; - if ( schemaTimestamp == null ) - { - schemaTimestamp = results[0] - .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ) != null ? results[0] - .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ).getStringValue() - : null; - } - String cacheTimestamp = schema.getModifyTimestamp() != null ? schema.getModifyTimestamp() - : schema.getCreateTimestamp(); - if ( cacheTimestamp == null - || ( cacheTimestamp != null && schemaTimestamp != null && schemaTimestamp - .compareTo( cacheTimestamp ) > 0 ) ) - { - ReloadSchemasJob.reloadSchema( browserConnection, monitor ); - } - } - else - { - browserConnection.setSchema( Schema.DEFAULT_SCHEMA ); - monitor.reportError( BrowserCoreMessages.model__no_schema_information ); - } - } - else - { - browserConnection.setSchema( Schema.DEFAULT_SCHEMA ); - monitor.reportError( BrowserCoreMessages.model__missing_schema_location ); - } - } - catch ( Exception e ) - { - browserConnection.setSchema( Schema.DEFAULT_SCHEMA ); - monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e ); - e.printStackTrace(); - } - } } Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java?rev=663698&r1=663697&r2=663698&view=diff ============================================================================== --- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java (original) +++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java Thu Jun 5 11:58:13 2008 @@ -21,6 +21,10 @@ package org.apache.directory.studio.ldapbrowser.core.jobs; +import javax.naming.NamingEnumeration; +import javax.naming.directory.Attribute; +import javax.naming.directory.SearchResult; + import org.apache.directory.shared.ldap.name.LdapDN; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.StudioProgressMonitor; @@ -94,14 +98,9 @@ { browserConnection.getConnection().getName() } ) ); monitor.worked( 1 ); - // load root DSE - monitor.reportProgress( BrowserCoreMessages.model__loading_rootdse ); - InitializeAttributesJob.initializeAttributes( browserConnection.getRootDSE(), true, monitor ); - monitor.worked( 1 ); - // load schema monitor.reportProgress( BrowserCoreMessages.model__loading_schema ); - reloadSchema( browserConnection, monitor ); + reloadSchema( true, browserConnection, monitor ); monitor.worked( 1 ); } @@ -124,25 +123,39 @@ { return BrowserCoreMessages.jobs__reload_schemas_error_1; } - + /** * Reloads the schema. * + * @param forceReload true to force the reload of the schema, otherwise it would only be reloaded + * if the server-side schema is newer than the cached schema. * @param browserConnection the browser connection * @param monitor the progress monitor */ - public static void reloadSchema( IBrowserConnection browserConnection, StudioProgressMonitor monitor ) + public static void reloadSchema( boolean forceReload, IBrowserConnection browserConnection, + StudioProgressMonitor monitor ) { - browserConnection.setSchema( Schema.DEFAULT_SCHEMA ); + LdapDN schemaLocation = getSchemaLocation( browserConnection, monitor ); + if ( schemaLocation == null ) + { + monitor.reportError( BrowserCoreMessages.model__missing_schema_location ); + return; + } - try + Schema schema = browserConnection.getSchema(); + + boolean mustReload = forceReload || ( schema == Schema.DEFAULT_SCHEMA ) + || mustReload( schemaLocation, browserConnection, monitor ); + + if ( mustReload ) { - if ( browserConnection.getRootDSE().getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) != null ) + browserConnection.setSchema( Schema.DEFAULT_SCHEMA ); + + try { SearchParameter sp = new SearchParameter(); - sp.setSearchBase( new LdapDN( browserConnection.getRootDSE().getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) - .getStringValue() ) ); + sp.setSearchBase( schemaLocation ); sp.setFilter( Schema.SCHEMA_FILTER ); sp.setScope( SearchScope.OBJECT ); sp.setReturningAttributes( new String[] @@ -150,26 +163,80 @@ Schema.SCHEMA_ATTRIBUTE_LDAPSYNTAXES, Schema.SCHEMA_ATTRIBUTE_MATCHINGRULES, Schema.SCHEMA_ATTRIBUTE_MATCHINGRULEUSE, IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP, IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP, } ); - + LdifEnumeration le = ExportLdifJob.search( browserConnection, sp, monitor ); if ( le.hasNext() ) { LdifContentRecord schemaRecord = ( LdifContentRecord ) le.next(); - Schema schema = new Schema(); + schema = new Schema(); schema.loadFromRecord( schemaRecord ); browserConnection.setSchema( schema ); - // TODO: Schema update event -// EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this, -// ConnectionUpdateEvent.EventDetail.SCHEMA_LOADED ), this ); } else { monitor.reportError( BrowserCoreMessages.model__no_schema_information ); } } - else + catch ( Exception e ) { - monitor.reportError( BrowserCoreMessages.model__missing_schema_location ); + monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e ); + e.printStackTrace(); + } + } + } + + + /** + * Checks if the schema must be reloaded + * + * @param browserConnection the browser connection + * @param monitor the progress monitor + */ + private static boolean mustReload( LdapDN schemaLocation, IBrowserConnection browserConnection, + StudioProgressMonitor monitor ) + { + Schema schema = browserConnection.getSchema(); + + try + { + SearchParameter sp = new SearchParameter(); + sp.setSearchBase( schemaLocation ); + sp.setFilter( Schema.SCHEMA_FILTER ); + sp.setScope( SearchScope.OBJECT ); + sp + .setReturningAttributes( new String[] + { IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP, + IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP } ); + NamingEnumeration enumeration = SearchJob.search( browserConnection, sp, monitor ); + while ( enumeration != null && enumeration.hasMore() ) + { + String createTimestamp = null; + String modifyTimestamp = null; + + SearchResult sr = enumeration.next(); + NamingEnumeration attributes = sr.getAttributes().getAll(); + while ( attributes.hasMore() ) + { + Attribute attribute = attributes.next(); + if ( attribute.getID().equalsIgnoreCase( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ) ) + { + modifyTimestamp = ( String ) attribute.get(); + } + if ( attribute.getID().equalsIgnoreCase( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ) ) + { + createTimestamp = ( String ) attribute.get(); + } + } + + String schemaTimestamp = modifyTimestamp != null ? modifyTimestamp : createTimestamp; + String cacheTimestamp = schema.getModifyTimestamp() != null ? schema.getModifyTimestamp() : schema + .getCreateTimestamp(); + if ( cacheTimestamp == null + || ( cacheTimestamp != null && schemaTimestamp != null && schemaTimestamp + .compareTo( cacheTimestamp ) > 0 ) ) + { + return true; + } } } catch ( Exception e ) @@ -177,5 +244,47 @@ monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e ); e.printStackTrace(); } + + return false; + } + + + private static LdapDN getSchemaLocation( IBrowserConnection browserConnection, StudioProgressMonitor monitor ) + { + try + { + SearchParameter sp = new SearchParameter(); + sp.setSearchBase( new LdapDN() ); + sp.setScope( SearchScope.OBJECT ); + sp.setReturningAttributes( new String[] + { IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY } ); + NamingEnumeration enumeration = SearchJob.search( browserConnection, sp, monitor ); + while ( enumeration != null && enumeration.hasMore() ) + { + SearchResult sr = enumeration.next(); + NamingEnumeration attributes = sr.getAttributes().getAll(); + while ( attributes.hasMore() ) + { + Attribute attribute = attributes.next(); + if ( attribute.getID().equalsIgnoreCase( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) ) + { + String value = ( String ) attribute.get(); + if ( LdapDN.isValid( value ) ) + { + LdapDN dn = new LdapDN( value ); + return dn; + } + } + } + } + } + catch ( Exception e ) + { + monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e ); + return null; + } + + return null; } + } Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java?rev=663698&r1=663697&r2=663698&view=diff ============================================================================== --- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java (original) +++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java Thu Jun 5 11:58:13 2008 @@ -142,7 +142,6 @@ entryToChildrenInfoMap.clear(); entryToChildrenFilterMap.clear(); - schema = Schema.DEFAULT_SCHEMA; rootDSE = new RootDSE( this ); cacheEntry( rootDSE ); Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/properties/SchemaPropertyPage.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/properties/SchemaPropertyPage.java?rev=663698&r1=663697&r2=663698&view=diff ============================================================================== --- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/properties/SchemaPropertyPage.java (original) +++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/properties/SchemaPropertyPage.java Thu Jun 5 11:58:13 2008 @@ -33,8 +33,8 @@ import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.ldapbrowser.core.utils.Utils; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; @@ -45,24 +45,41 @@ import org.eclipse.ui.dialogs.PropertyPage; +/** + * Property page to shows some meta information of the schema an the + * schema cache. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ public class SchemaPropertyPage extends PropertyPage implements IWorkbenchPropertyPage { + /** Text field containing the DN of the schema entry. */ private Text dnText; + /** Text field containing the create timestamp of the schema entry. */ private Text ctText; + /** Text field containing the modify timestamp of the schema entry. */ private Text mtText; + /** Button to reload the scheam. */ private Button reloadSchemaButton; + /** Text field containing the path to the schema cache file. */ private Text cachePathText; + /** Text field containing last modify date of the schema cache file. */ private Text cacheDateText; + /** Text field containing the size of the schema cache file. */ private Text cacheSizeText; + /** + * Instantiates a new schema property page. + */ public SchemaPropertyPage() { super(); @@ -70,9 +87,11 @@ } + /** + * {@inheritDoc} + */ protected Control createContents( Composite parent ) { - Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); Group infoGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ), @@ -93,17 +112,12 @@ GridData gd = new GridData(); gd.verticalAlignment = SWT.BOTTOM; reloadSchemaButton.setLayoutData( gd ); - reloadSchemaButton.addSelectionListener( new SelectionListener() + reloadSchemaButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { reloadSchema(); } - - - public void widgetDefaultSelected( SelectionEvent e ) - { - } } ); BaseWidgetUtils.createSpacer( composite, 1 ); @@ -123,25 +137,32 @@ cacheSizeText = BaseWidgetUtils.createWrappedLabeledText( cacheComposite, "", 1 ); IBrowserConnection connection = RootDSEPropertyPage.getConnection( getElement() ); - this.connectionUpdated( connection ); + update( connection ); return composite; } + /** + * Reloads schema. + */ private void reloadSchema() { final IBrowserConnection browserConnection = RootDSEPropertyPage.getConnection( getElement() ); ReloadSchemasJob job = new ReloadSchemasJob( browserConnection ); RunnableContextJobAdapter.execute( job ); - this.connectionUpdated( browserConnection ); + update( browserConnection ); } - private void connectionUpdated( IBrowserConnection connection ) + /** + * Updates the text fields. + * + * @param connection the connection + */ + private void update( IBrowserConnection connection ) { - - if ( !this.dnText.isDisposed() ) + if ( !dnText.isDisposed() ) { Schema schema = null; if ( connection != null ) @@ -209,9 +230,14 @@ } + /** + * Checks if is disposed. + * + * @return true, if is disposed + */ public boolean isDisposed() { - return this.dnText.isDisposed(); + return dnText.isDisposed(); } }