Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package net.java.ao.schema;
  
  
  import java.util.List;
  
 import static com.google.common.base.Preconditions.*;
 import static com.google.common.collect.Lists.*;
 import static java.util.regex.Pattern.*;

A simple table name converter which imposes a set of regular-expression rules to pluralize names generated by the delegate converter.

Unfortunately, due to complexities innate to the English language, automatic pluralization is never very accurate. The sheer number of irregular nouns, coupled with the different conjugations which can unrecognizably mangle even an "every day" noun makes it extremely difficult to define generic rules which can control pluralization. ActiveObjects attempts to uphold the highest standards of quality in its pluralization engine by imposing rigorous tests using a wide variety of dictionary words. However, the pluralization should be considered experimental at best.

To enable table name pluralization, simply set the name converter for the net.java.ao.EntityManager in question to an instance of this class.

 
 {
     private TableNameConverter delegate;
 
     public PluralizedTableNameConverter()
     {
         this(new ClassNameTableNameConverter());
     }
 
     public PluralizedTableNameConverter(CanonicalClassNameTableNameConverter delegateTableNameConverter)
     {
         super(transforms(), delegateTableNameConverter);
         this. = delegateTableNameConverter;
     }
 
     private static List<Transformtransforms()
     {
         final OrderedProperties patterns = OrderedProperties.load("/net/java/ao/schema/englishPluralRules.properties");
         return Lists.transform(newArrayList(patterns), new Function<StringTransform>()
         {
             public Transform apply(String from)
             {
                 return new PatternTransform(frompatterns.get(from));
             }
         });
     }
 
     /*
      * TODO why?!?!
      */
     public TableNameConverter getDelegate()
     {
         return ;
     }

    
 
     static final class PatternTransform implements Transform
     {
         private static final Pattern PLACE_HOLDER_PATTERN = compile("(\\{\\})");
 
         private final Pattern patternToMatch;
         private final String transformationPattern;
 
         PatternTransform(String patternToMatchString transformationPattern)
         {
             checkNotNull(patternToMatch);
             this. = compile(patternToMatch.);
             this. = checkNotNull(transformationPattern);
         }
 
         public boolean accept(String entityClassCanonicalName)
         {
             return .matcher(entityClassCanonicalName).matches();
         }
 
         public String apply(String entityClassCanonicalName)
         {
             return transform(entityClassCanonicalName);
         }
 
         static String transform(Pattern patternToMatchString currentStringString transformationPattern)
         {
             final Matcher m = patternToMatch.matcher(currentString);
             if (m.matches())
             {
                 return replacePlaceHolders(transformationPatternm.group(1));
             }
             else
            {
                return currentString;
            }
        }
        static String replacePlaceHolders(String stringWithPlaceHoldersString value)
        {
            return .matcher(stringWithPlaceHolders).replaceAll(value);
        }
    }
New to GrepCode? Check out our FAQ X