directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1070883 - /directory/shared/branches/m1/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schemaloader/JarLdifSchemaLoader.java
Date Tue, 15 Feb 2011 13:26:15 GMT
Author: elecharny
Date: Tue Feb 15 13:26:15 2011
New Revision: 1070883

URL: http://svn.apache.org/viewvc?rev=1070883&view=rev
Log:
Sped up the schema loading by getting rid of Pattern matching. It goes twice faster now.

Modified:
    directory/shared/branches/m1/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schemaloader/JarLdifSchemaLoader.java

Modified: directory/shared/branches/m1/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schemaloader/JarLdifSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schemaloader/JarLdifSchemaLoader.java?rev=1070883&r1=1070882&r2=1070883&view=diff
==============================================================================
--- directory/shared/branches/m1/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schemaloader/JarLdifSchemaLoader.java
(original)
+++ directory/shared/branches/m1/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schemaloader/JarLdifSchemaLoader.java
Tue Feb 15 13:26:15 2011
@@ -71,7 +71,7 @@ public class JarLdifSchemaLoader extends
 
     /** a map of all the resources in this jar */
     private static final Map<String, Boolean> RESOURCE_MAP = ResourceMap.getResources(
Pattern
-        .compile( ".*schema" + SEPARATOR_PATTERN + "ou=schema.*" ) );
+        .compile( "schema" + SEPARATOR_PATTERN + "ou=schema.*" ) );
 
 
     /**
@@ -114,7 +114,7 @@ public class JarLdifSchemaLoader extends
             LOG.debug( "Initializing schema" );
         }
 
-        Pattern pat = Pattern.compile( ".*schema" + SEPARATOR_PATTERN + "ou=schema"
+        Pattern pat = Pattern.compile( "schema" + SEPARATOR_PATTERN + "ou=schema"
                 + SEPARATOR_PATTERN + "cn=[a-z0-9-_]*\\." + LDIF_EXT );
 
         for ( String file : RESOURCE_MAP.keySet() )
@@ -157,10 +157,10 @@ public class JarLdifSchemaLoader extends
      * @param schema the schema to get the path for
      * @return the regex.Pattern fragment for the path for the specified schema directory
      */
-    private String getSchemaDirectory( Schema schema )
+    private String getSchemaDirectoryString( Schema schema )
     {
-        return "schema" + SEPARATOR_PATTERN + "ou=schema" + SEPARATOR_PATTERN
-                        + "cn=" + Strings.lowerCase(schema.getSchemaName()) + SEPARATOR_PATTERN;
+        return "schema" + File.separator + "ou=schema" + File.separator
+                        + "cn=" + Strings.lowerCase(schema.getSchemaName()) + File.separator;
     }
 
 
@@ -178,12 +178,13 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
-                    + SchemaConstants.COMPARATORS_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
+            String start = getSchemaDirectoryString( schema )
+                + SchemaConstants.COMPARATORS_PATH + File.separator + "m-oid=";
+            String end = "." + LDIF_EXT;
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                if ( regex.matcher( resourcePath ).matches() )
+                if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end
) )
                 {
                     URL resource = getResource( resourcePath, "comparator LDIF file" );
                     LdifReader reader = new LdifReader( resource.openStream() );
@@ -213,12 +214,13 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
-                    + SchemaConstants.SYNTAX_CHECKERS_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
+            String start = getSchemaDirectoryString( schema )
+                + SchemaConstants.SYNTAX_CHECKERS_PATH + File.separator + "m-oid=";
+            String end = "." + LDIF_EXT;
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                if ( regex.matcher( resourcePath ).matches() )
+                if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end
) )
                 {
                     URL resource = getResource( resourcePath, "syntaxChecker LDIF file" );
                     LdifReader reader = new LdifReader( resource.openStream() );
@@ -248,12 +250,13 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
-                    + SchemaConstants.NORMALIZERS_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
+            String start = getSchemaDirectoryString( schema )
+                + SchemaConstants.NORMALIZERS_PATH + File.separator + "m-oid=";
+            String end = "." + LDIF_EXT;
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                if ( regex.matcher( resourcePath ).matches() )
+                if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end
) )
                 {
                     URL resource = getResource( resourcePath, "normalizer LDIF file" );
                     LdifReader reader = new LdifReader( resource.openStream() );
@@ -283,12 +286,13 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
-                    + SchemaConstants.MATCHING_RULES_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
+            String start = getSchemaDirectoryString( schema )
+                + SchemaConstants.MATCHING_RULES_PATH + File.separator + "m-oid=";
+            String end = "." + LDIF_EXT;
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                if ( regex.matcher( resourcePath ).matches() )
+                if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end
) )
                 {
                     URL resource = getResource( resourcePath, "matchingRules LDIF file" );
                     LdifReader reader = new LdifReader( resource.openStream() );
@@ -318,12 +322,13 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
-                    + SchemaConstants.SYNTAXES_PATH + SEPARATOR_PATTERN + "m-oid=.*\\." +
LDIF_EXT );
+            String start = getSchemaDirectoryString( schema )
+                + SchemaConstants.SYNTAXES_PATH + File.separator + "m-oid=";
+            String end = "." + LDIF_EXT;
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                if ( regex.matcher( resourcePath ).matches() )
+                if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end
) )
                 {
                     URL resource = getResource( resourcePath, "syntax LDIF file" );
                     LdifReader reader = new LdifReader( resource.openStream() );
@@ -354,13 +359,14 @@ public class JarLdifSchemaLoader extends
         for ( Schema schema : schemas )
         {
             // check that the attributeTypes directory exists for the schema
-            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
-                    + SchemaConstants.ATTRIBUTES_TYPE_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
-
+            String start = getSchemaDirectoryString( schema )
+                    + SchemaConstants.ATTRIBUTES_TYPE_PATH + File.separator + "m-oid=";
+            String end = "." + LDIF_EXT;
+            
             // get list of attributeType LDIF schema files in attributeTypes
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                if ( regex.matcher( resourcePath ).matches() )
+                if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end
) )
                 {
                     URL resource = getResource( resourcePath, "attributeType LDIF file" );
                     LdifReader reader = new LdifReader( resource.openStream() );
@@ -390,12 +396,13 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
-                    + SchemaConstants.MATCHING_RULE_USE_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
+            String start = getSchemaDirectoryString( schema )
+                + SchemaConstants.MATCHING_RULE_USE_PATH + File.separator + "m-oid=";
+            String end = "." + LDIF_EXT;
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                if ( regex.matcher( resourcePath ).matches() )
+                if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end
) )
                 {
                     URL resource = getResource( resourcePath, "matchingRuleUse LDIF file"
);
                     LdifReader reader = new LdifReader( resource.openStream() );
@@ -425,12 +432,13 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
-                    + SchemaConstants.NAME_FORMS_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
+            String start = getSchemaDirectoryString( schema )
+                + SchemaConstants.NAME_FORMS_PATH + File.separator + "m-oid=";
+            String end = "." + LDIF_EXT;
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                if ( regex.matcher( resourcePath ).matches() )
+                if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end
) )
                 {
                     URL resource = getResource( resourcePath, "nameForm LDIF file" );
                     LdifReader reader = new LdifReader( resource.openStream() );
@@ -460,12 +468,13 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
-                    + SchemaConstants.DIT_CONTENT_RULES_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
+            String start = getSchemaDirectoryString( schema )
+                + SchemaConstants.DIT_CONTENT_RULES_PATH + File.separator + "m-oid=";
+            String end = "." + LDIF_EXT;
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                if ( regex.matcher( resourcePath ).matches() )
+                if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end
) )
                 {
                     URL resource = getResource( resourcePath, "ditContentRule LDIF file"
);
                     LdifReader reader = new LdifReader( resource.openStream() );
@@ -495,13 +504,13 @@ public class JarLdifSchemaLoader extends
 
         for ( Schema schema : schemas )
         {
-            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
-                    + SchemaConstants.DIT_STRUCTURE_RULES_PATH
-                                                + SEPARATOR_PATTERN + "m-oid=.*\\." + LDIF_EXT
);
+            String start = getSchemaDirectoryString( schema )
+                + SchemaConstants.DIT_STRUCTURE_RULES_PATH + File.separator + "m-oid=";
+            String end = "." + LDIF_EXT;
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                if ( regex.matcher( resourcePath ).matches() )
+                if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end
) )
                 {
                     URL resource = getResource( resourcePath, "ditStructureRule LDIF file"
);
                     LdifReader reader = new LdifReader( resource.openStream() );
@@ -532,12 +541,13 @@ public class JarLdifSchemaLoader extends
         for ( Schema schema : schemas )
         {
             // get objectClasses directory, check if exists, return if not
-            Pattern regex = Pattern.compile( ".*" + getSchemaDirectory( schema )
-                    + SchemaConstants.OBJECT_CLASSES_PATH + SEPARATOR_PATTERN + "m-oid=.*\\."
+ LDIF_EXT );
+            String start = getSchemaDirectoryString( schema )
+                + SchemaConstants.OBJECT_CLASSES_PATH + File.separator + "m-oid=";
+            String end = "." + LDIF_EXT;
 
             for ( String resourcePath : RESOURCE_MAP.keySet() )
             {
-                if ( regex.matcher( resourcePath ).matches() )
+                if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end
) )
                 {
                     URL resource = getResource( resourcePath, "objectClass LDIF file" );
                     LdifReader reader = new LdifReader( resource.openStream() );



Mime
View raw message