├── .gitignore ├── CHANGELOG ├── META-INF └── MANIFEST.MF ├── README.md ├── RELEASE.md ├── hbnpojogen-core ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ └── org.maven.ide.eclipse.prefs ├── META-INF │ └── MANIFEST.MF ├── assembly.xml ├── documentation │ └── website │ │ ├── build_model.sh │ │ ├── images │ │ ├── Thumbs.db │ │ ├── footer.png │ │ ├── headbanner.png │ │ ├── header-bg.png │ │ ├── highlightgreen.png │ │ ├── logo.png │ │ ├── menu-hvr.png │ │ ├── menu.png │ │ └── topheadbg.png │ │ ├── index.html │ │ └── style.css ├── pom.xml ├── sample.xml └── src │ └── main │ ├── java │ └── com │ │ └── github │ │ └── wwadge │ │ └── hbnpojogen │ │ ├── CascadeState.java │ │ ├── CascadeType.java │ │ ├── CaseInsensitiveComparator.java │ │ ├── Config.java │ │ ├── Constants.java │ │ ├── Core.java │ │ ├── CustomAnnotations.java │ │ ├── CustomDB.java │ │ ├── EnumMapping.java │ │ ├── EnumResult.java │ │ ├── FakeFKPattern.java │ │ ├── GeneratedValueFields.java │ │ ├── GeneratedValueSchemas.java │ │ ├── HbnPojoGen.java │ │ ├── ObjectPair.java │ │ ├── PackageMap.java │ │ ├── PackageTypeEnum.java │ │ ├── RelationItem.java │ │ ├── State.java │ │ ├── SyncUtils.java │ │ ├── VelocityHelper.java │ │ ├── VelocityTable.java │ │ ├── VelocityWriters.java │ │ ├── db │ │ ├── FieldObj.java │ │ ├── KeyObj.java │ │ └── TableObj.java │ │ └── obj │ │ ├── Clazz.java │ │ ├── GeneratorEnum.java │ │ ├── JoinTable.java │ │ ├── PropertyMeta.java │ │ └── PropertyObj.java │ └── resources │ ├── log4j.properties │ ├── synchronizer.version │ └── templates │ ├── BasicDataGenerator.vm │ ├── CustomRepository.vm │ ├── CustomRepositoryImpl.vm │ ├── IPojoGenEntity.vm │ ├── MockDatabase.vm │ ├── RepositoryFactoryBean.vm │ ├── StringValuedEnum.vm │ ├── StringValuedEnumReflect.vm │ ├── StringValuedEnumType.vm │ ├── applicationContext.vm │ ├── class.vm │ ├── classIface.vm │ ├── classRepo.vm │ ├── dao.vm │ ├── daoFactory.vm │ ├── daoInterface.vm │ ├── daotest.vm │ ├── dataPoolFactory.vm │ ├── dataPoolFactoryInterface.vm │ ├── datalayer.vm │ ├── dbVersionCheck.vm │ ├── ehcache.vm │ ├── enum.vm │ ├── enumClass.vm │ ├── hbnPojoGenBuild.vm │ ├── mocktest.vm │ ├── openapi-allpaths.vm │ ├── openapi-delegate.vm │ ├── openapi-reference-docs.vm │ ├── openapi-schema.vm │ ├── openapi-test.vm │ └── pom.vm ├── hbnpojogen-maven ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.maven.ide.eclipse.prefs ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── github │ └── wwadge │ └── hbnpojogen │ └── SynchronizerMojo.java ├── hbnpojogen-persistence ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ └── org.maven.ide.eclipse.prefs ├── META-INF │ └── MANIFEST.MF ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── github │ └── wwadge │ └── hbnpojogen │ ├── persistence │ ├── GenericDAO.java │ ├── IPojoGenEntity.java │ ├── impl │ │ ├── CustomGeneratedId.java │ │ ├── GenericHibernateDaoImpl.java │ │ ├── HibernateUtils.java │ │ ├── IDPresentAwareGenerator.java │ │ ├── StringValuedEnum.java │ │ ├── StringValuedEnumReflect.java │ │ └── StringValuedEnumType.java │ └── validator │ │ └── Mandatory.java │ └── randomlib │ └── data │ ├── CountryCodes.java │ └── dataGeneration │ ├── BasicDataGenerator.java │ └── ComplexDataTypes.java ├── inflector ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.maven.ide.eclipse.prefs ├── LICENSE.txt ├── bin │ ├── org │ │ └── jvnet │ │ │ └── inflector │ │ │ ├── package.html │ │ │ └── rule │ │ │ └── package.html │ └── overview.html ├── build.xml ├── maven.xml ├── pom.xml ├── project.properties └── src │ └── main │ └── java │ ├── org │ └── jvnet │ │ └── inflector │ │ ├── Noun.java │ │ ├── Pluralizer.java │ │ ├── Rule.java │ │ ├── RuleBasedPluralizer.java │ │ ├── lang │ │ ├── en │ │ │ └── NounPluralizer.java │ │ └── it │ │ │ └── NounPluralizer.java │ │ ├── package.html │ │ └── rule │ │ ├── AbstractRegexReplacementRule.java │ │ ├── CategoryInflectionRule.java │ │ ├── IrregularMappingRule.java │ │ ├── RegexReplacementRule.java │ │ ├── SuffixInflectionRule.java │ │ └── package.html │ └── overview.html └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | **/*.xml.versionsBackup 4 | # Package Files # 5 | .MySCMServerInfo 6 | **/*.java.rej 7 | *.orig 8 | *.reg 9 | *.java.reg 10 | *.orig.reg 11 | *.log 12 | velocity.log 13 | velocity.log.1 14 | target/ 15 | 16 | # IntelliJ 17 | .idea/ 18 | *.iml 19 | 20 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | Changelog 2 | --------- 3 | 4 | 5 | hbnpojogen-persistence v1.3.3: 6 | - Fixed Jetty classloading setup 7 | 8 | hbnpojogen v1.0.1 9 | - Fixed incorrect 2nd level cache setting in template 10 | 11 | hbnpojogen v1.0.2 12 | - Added noArtifactVersions support in maven pom output. 13 | 14 | hbnpojogen v1.0.3 15 | - Fixed dbversion bug in case of different sort order. 16 | 17 | hbnpojogen v1.0.4 18 | - Added JNDI support. 19 | 20 | hbnpojogen v1.0.6 21 | - LDAP support 22 | - Synchronizer version in pom.xml 23 | - DAOTest -> DAOIntegrationTest 24 | 25 | hbnpojogen v1.0.8 26 | - Don't generate hashcode for subclasses. 27 | 28 | hbnpojogen v1.0.9 29 | - Support version checking using >= too 30 | 31 | hbnpojogen v1.0.10 32 | - Manual saves in daotest: add support for problematic OneToOne too 33 | - Add extra meta-data to fail early on nullables in joinColumns 34 | 35 | -------------------------------------------------------------------------------- /META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: hbnpojogen 4 | Bundle-SymbolicName: hbnpojogen 5 | Bundle-Version: 1.0.0 6 | Export-Package: com.github.wwadge.hbnpojogen, 7 | com.github.wwadge.hbnpojogen.db, 8 | com.github.wwadge.hbnpojogen.obj, 9 | com.github.wwadge.hbnpojogen.persistence, 10 | com.github.wwadge.hbnpojogen.persistence.impl, 11 | com.github.wwadge.hbnpojogen.persistence.validator, 12 | com.github.wwadge.hbnpojogen.randomlib.data, 13 | com.github.wwadge.hbnpojogen.randomlib.data.dataGeneration 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | hbnpojogen 2 | ========== 3 | 4 | Hibernate Pojo Generator 5 | 6 | What does it do? 7 | ================ 8 | 9 | Given an accessible database schema, the Hibernate POJO Generator produces all the Java code necessary to access each field in each table via the Hibernate persistence framework. Additionally, the generator also creates all the necessary helper classes and test units for each component. 10 | 11 | Features 12 | ======== 13 | 14 | Given a source database, Hibernate POJO Generator (hbnPojoGen) generates: 15 | 16 | - Java objects representing each table using annotations for use with Hibernate. 17 | - A JUnit test case per table that uses the objects generated to create, populate, save, retrieve and compare results 18 | - DAO per class 19 | - The appropriate enumeration files 20 | - Spring and hibernate configuration 21 | - DAO layers 22 | - A data factory class per schema to return a pre-populated object with random data (for boundary checking, database population, etc) 23 | 24 | Also supports 25 | - Join tables including those with additional fields in link tables 26 | - Polymorphism/inheritance support 27 | - Composite Keys 28 | - One-To-One, many-to-one, many-to-many, etc 29 | - Multiple schema support (4 modes) 30 | - Natural Keys 31 | - Enumerations (including those entries which cannot be mapped cleanly onto the java world) 32 | - A whole bunch of more stuff (see [sample.xml](./hbnpojogen-core/sample.xml)) 33 | 34 | Please see sample.xml for a very documented list of available features. 35 | -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | For gpg signing to work: 2 | 3 | eval $(gpg-agent --daemon --no-grab --write-env-file $HOME/.gpg-agent-info) 4 | export GPG_TTY=$(tty) 5 | export GPG_AGENT_INFO -------------------------------------------------------------------------------- /hbnpojogen-core/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /hbnpojogen-core/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | hbnpojogen-core 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.openarchitectureware.xsd.plugin.xsdBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.ManifestBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.pde.SchemaBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jdt.core.javanature 36 | org.eclipse.pde.PluginNature 37 | org.eclipse.m2e.core.maven2Nature 38 | 39 | 40 | -------------------------------------------------------------------------------- /hbnpojogen-core/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Mon Apr 23 11:22:58 CEST 2012 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.compliance=1.6 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.source=1.6 7 | -------------------------------------------------------------------------------- /hbnpojogen-core/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /hbnpojogen-core/.settings/org.maven.ide.eclipse.prefs: -------------------------------------------------------------------------------- 1 | #Tue May 31 10:30:32 CEST 2011 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | fullBuildGoals=process-test-resources 5 | includeModules=false 6 | resolveWorkspaceProjects=true 7 | resourceFilterGoals=process-resources resources\:testResources 8 | skipCompilerPlugin=true 9 | version=1 10 | -------------------------------------------------------------------------------- /hbnpojogen-core/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Plugin Plug-in 4 | Bundle-SymbolicName: com.github.wwadge.hbnpojogen.plugin.synchronizer;singleton:=true 5 | Bundle-Version: 1.0.0 6 | Bundle-ClassPath: . 7 | Main-Class: com.github.wwadge.hbnpojogen.HbnPojoGen 8 | Export-Package: com.github.wwadge.hbnpojogen, 9 | com.github.wwadge.hbnpojogen.db, 10 | com.github.wwadge.hbnpojogen.obj 11 | 12 | -------------------------------------------------------------------------------- /hbnpojogen-core/assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | jar-with-dependencies 3 | 4 | jar 5 | 6 | 7 | false 8 | 9 | 10 | true 11 | runtime 12 | 13 | 14 | -------------------------------------------------------------------------------- /hbnpojogen-core/documentation/website/build_model.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Note: tmpwatch is configured to clean out output folder after some time 3 | if [ "$(whoami)" != "root" ]; then 4 | echo "Sorry, you are not root." 5 | exit 1 6 | fi 7 | if [ $# -lt 1 ] 8 | then 9 | echo "Usage: `basename $0` [nodeploy]" 10 | exit 1 11 | fi 12 | JAVA_HOME=/var/jdk 13 | TOPLEVEL=/var/www/html/generator 14 | WATCHDIR=$TOPLEVEL/$1 15 | mkdir $WATCHDIR 16 | chown apache.ci $WATCHDIR 17 | while [ 1 ]; do 18 | WATCH=`inotifywait -e close_write --format '%w,%f' $WATCHDIR` 19 | lockfile $WATCHDIR/WORKING 20 | DIR=`echo $WATCH | cut -f 1 -d ','` 21 | FILE=`echo $WATCH | cut -f 2 -d ','` 22 | rm $DIR/output -rf 23 | rm -f $DIR/status.html $DIR/WAITING-FOR-NEW-FILE $DIR/ARTIFACT-EXISTS-NOT-DEPLOYING $DIR/SNAPSHOT-ARTIFACT-DEPLOYED-* $DIR/ARTIFACT-DEPLOYED-* $DIR/MAVEN-ERROR-CHECK-STATUS 24 | cd /var/cruisecontrol/projects/HbnPojoGen 25 | TEMP=`mktemp -d` 26 | echo "
`date`" > $DIR/status.html
27 | java -jar ./hbnPojoGen.jar $DIR/$FILE $TEMP >> $DIR/status.html 2>&1 
28 | if [ $# -eq 1 ]; then 
29 | ## Now check if the generated pom will overwrite an existing artifact and if so bail out.
30 | GROUPID=`xmllint --format $DIR/$FILE  | grep "> $DIR/status.html
37 | if [ -d /var/archiva/data/repositories/repo/$GROUPID/$ARTIFACTID/$VERSION ]; then
38 | 	echo "Artifact already exists - not deploying!" >> $DIR/status.html
39 | 	touch $DIR/ARTIFACT-EXISTS-NOT-DEPLOYING
40 | else
41 | 	touch $DIR/MAVEN-IS-BUILDING
42 | 	mvn -f $TEMP/pom.xml deploy >> $DIR/status.html 2>&1 
43 | 	if [ "$?" -ne "1" ]; then
44 | 		touch $DIR/ARTIFACT-DEPLOYED-$ARTIFACTID-$VERSION 
45 | 		rm $DIR/MAVEN-IS-BUILDING
46 | 	else 
47 | 		touch $DIR/MAVEN-ERROR-CHECK-STATUS
48 | 	fi
49 | fi
50 | else
51 | 	touch $DIR/MAVEN-IS-BUILDING
52 |         mvn -f $TEMP/pom.xml deploy >> $DIR/status.html 2>&1 
53 |         if [ "$?" -ne "1" ]; then
54 |                 touch $DIR/SNAPSHOT-ARTIFACT-DEPLOYED-$ARTIFACTID-$VERSION
55 |                 rm $DIR/MAVEN-IS-BUILDING
56 |         else
57 |                 touch $DIR/MAVEN-ERROR-CHECK-STATUS
58 |         fi
59 | 
60 | fi
61 | 
62 | 
63 | fi
64 | find $TEMP -name '*.java' | xargs unix2dos
65 | mv $TEMP $DIR/output
66 | chmod ogu-w $DIR/status.html
67 | echo "
" >> $DIR/status.html 68 | # Make it windows friendly 69 | unix2dos $DIR/status.html 70 | rm $DIR/$FILE -f 71 | chmod o+rwx -R $DIR/output 72 | rm -f $DIR/WORKING 73 | touch $DIR/WAITING-FOR-NEW-FILE 74 | done 75 | -------------------------------------------------------------------------------- /hbnpojogen-core/documentation/website/images/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwadge/hbnpojogen/e668c4fa5ac1ab41e8e5f3a6dd99efc733eb4049/hbnpojogen-core/documentation/website/images/Thumbs.db -------------------------------------------------------------------------------- /hbnpojogen-core/documentation/website/images/footer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwadge/hbnpojogen/e668c4fa5ac1ab41e8e5f3a6dd99efc733eb4049/hbnpojogen-core/documentation/website/images/footer.png -------------------------------------------------------------------------------- /hbnpojogen-core/documentation/website/images/headbanner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwadge/hbnpojogen/e668c4fa5ac1ab41e8e5f3a6dd99efc733eb4049/hbnpojogen-core/documentation/website/images/headbanner.png -------------------------------------------------------------------------------- /hbnpojogen-core/documentation/website/images/header-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwadge/hbnpojogen/e668c4fa5ac1ab41e8e5f3a6dd99efc733eb4049/hbnpojogen-core/documentation/website/images/header-bg.png -------------------------------------------------------------------------------- /hbnpojogen-core/documentation/website/images/highlightgreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwadge/hbnpojogen/e668c4fa5ac1ab41e8e5f3a6dd99efc733eb4049/hbnpojogen-core/documentation/website/images/highlightgreen.png -------------------------------------------------------------------------------- /hbnpojogen-core/documentation/website/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwadge/hbnpojogen/e668c4fa5ac1ab41e8e5f3a6dd99efc733eb4049/hbnpojogen-core/documentation/website/images/logo.png -------------------------------------------------------------------------------- /hbnpojogen-core/documentation/website/images/menu-hvr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwadge/hbnpojogen/e668c4fa5ac1ab41e8e5f3a6dd99efc733eb4049/hbnpojogen-core/documentation/website/images/menu-hvr.png -------------------------------------------------------------------------------- /hbnpojogen-core/documentation/website/images/menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwadge/hbnpojogen/e668c4fa5ac1ab41e8e5f3a6dd99efc733eb4049/hbnpojogen-core/documentation/website/images/menu.png -------------------------------------------------------------------------------- /hbnpojogen-core/documentation/website/images/topheadbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwadge/hbnpojogen/e668c4fa5ac1ab41e8e5f3a6dd99efc733eb4049/hbnpojogen-core/documentation/website/images/topheadbg.png -------------------------------------------------------------------------------- /hbnpojogen-core/documentation/website/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwadge/hbnpojogen/e668c4fa5ac1ab41e8e5f3a6dd99efc733eb4049/hbnpojogen-core/documentation/website/index.html -------------------------------------------------------------------------------- /hbnpojogen-core/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 4.0.0 5 | 6 | com.github.wwadge 7 | hbnpojogen-core 8 | 9 | 10 | hbnpojogen 11 | com.github.wwadge 12 | 1.5.13 13 | 14 | 15 | Hibernate POJO Generator Core 16 | The core class files of Hibernate POJO Generator. 17 | 18 | 19 | 20 | commons-configuration 21 | commons-configuration 22 | 23 | 24 | 25 | net.sourceforge.jtds 26 | jtds 27 | 28 | 29 | 30 | 31 | org.postgresql 32 | postgresql 33 | 34 | 35 | 36 | 37 | commons-io 38 | commons-io 39 | 40 | 41 | 42 | commons-lang 43 | commons-lang 44 | 45 | 46 | 47 | net.java.dev.inflector 48 | inflector 49 | 50 | 51 | 52 | com.google.guava 53 | guava 54 | 55 | 56 | 57 | mysql 58 | mysql-connector-java 59 | true 60 | 61 | 62 | 63 | org.apache.velocity 64 | velocity 65 | 66 | 67 | 68 | log4j 69 | log4j 70 | 71 | 72 | jmxtools 73 | com.sun.jdmk 74 | 75 | 76 | 77 | 78 | 79 | org.apache.maven 80 | maven-plugin-api 81 | 82 | 83 | 84 | 85 | 86 | 87 | src/main/resources 88 | true 89 | 90 | **/synchronizer.version 91 | 92 | 93 | 94 | 95 | src/main/resources 96 | false 97 | 98 | **/synchronizer.version 99 | 100 | 101 | 102 | 103 | 104 | 105 | maven-assembly-plugin 106 | 2.2-beta-5 107 | 108 | 109 | package 110 | 111 | single 112 | 113 | 114 | 115 | META-INF/MANIFEST.MF 116 | 117 | 118 | 119 | assembly.xml 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | local-build 135 | 136 | 137 | env.ECLIPSE_HOME 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | maven-assembly-plugin 146 | 147 | 148 | install 149 | 150 | single 151 | 152 | 153 | 154 | META-INF/MANIFEST.MF 155 | 156 | 157 | ${env.ECLIPSE_HOME}\plugins 158 | 159 | assembly.xml 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/CascadeState.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen; 2 | 3 | import java.io.Serializable; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | 8 | /** 9 | * @author wallacew 10 | * @version $Revision: 2$ 11 | */ 12 | public class CascadeState implements Serializable { 13 | 14 | /** */ 15 | private static final long serialVersionUID = -8188145324423752745L; 16 | private boolean cascadeEnabled; 17 | private Set cascadeType = new HashSet(); 18 | 19 | public CascadeState(boolean cascadeEnabled, Set cascadeType) { 20 | this.cascadeEnabled = cascadeEnabled; 21 | this.cascadeType = cascadeType; 22 | } 23 | 24 | public CascadeState(boolean cascadeEnabled, String cascadeType) { 25 | this.cascadeEnabled = cascadeEnabled; 26 | this.cascadeType.add(cascadeType); 27 | } 28 | 29 | /** 30 | * Gets 31 | * 32 | * @return 33 | */ 34 | public boolean isCascadeEnabled() { 35 | return this.cascadeEnabled; 36 | } 37 | 38 | /** 39 | * Sets 40 | * 41 | * @param cascadeEnabled 42 | */ 43 | public void setCascadeEnabled(boolean cascadeEnabled) { 44 | this.cascadeEnabled = cascadeEnabled; 45 | } 46 | 47 | /** 48 | * Gets 49 | * 50 | * @return 51 | */ 52 | public Set getCascadeType() { 53 | return this.cascadeType; 54 | } 55 | 56 | /** 57 | * Sets 58 | * 59 | * @param cascadeType 60 | */ 61 | public void setCascadeType(Set cascadeType) { 62 | this.cascadeType = cascadeType; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "cascade=" + cascadeEnabled + ", cascade=" + cascadeType.toString(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/CascadeType.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen; 2 | 3 | 4 | /** 5 | * @author wallacew 6 | * @version $Revision: 1$ 7 | */ 8 | public enum CascadeType { 9 | CASCADE_ALL, 10 | CASCADE_NONE, 11 | CASCADE_PERSIST, 12 | CASCADE_MERGE, 13 | CASCADE_REMOVE 14 | } 15 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/CaseInsensitiveComparator.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen; 2 | 3 | import java.io.Serializable; 4 | import java.util.Comparator; 5 | 6 | /** 7 | * To make treemap case insensitive 8 | * 9 | * @author wallacew 10 | */ 11 | public class CaseInsensitiveComparator implements Comparator, Serializable { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = -1963338405421574150L; 17 | 18 | @Override 19 | public int compare(String o1, String o2) { 20 | return o1.toUpperCase().compareTo(o2.toUpperCase()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/Constants.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen; 2 | 3 | /** 4 | * Various contants 5 | * 6 | * @author wallacew 7 | */ 8 | public class Constants { 9 | 10 | /** 11 | * Constant 12 | */ 13 | static final String DATABASE_TYPE = "dbType"; 14 | /** 15 | * Constant 16 | */ 17 | static final String LIB_PATH = "libPath"; 18 | /** 19 | * Constant 20 | */ 21 | static final String TYPE_NAME = "TYPE_NAME"; 22 | /** 23 | * Constant 24 | */ 25 | static final String JDBC_CONNECTION_STRING = "jdbcConnectionString"; 26 | /** 27 | * Constant 28 | */ 29 | static final String FK_NAME = "FK_NAME"; 30 | /** 31 | * Constant 32 | */ 33 | static final String PKTABLE_NAME = "PKTABLE_NAME"; 34 | /** 35 | * Constant 36 | */ 37 | static final String PKCOLUMN_NAME = "PKCOLUMN_NAME"; 38 | /** 39 | * Constant 40 | */ 41 | static final String KEY_SEQ = "KEY_SEQ"; 42 | /** 43 | * Constant 44 | */ 45 | static final String DATABASE_IP = "databaseIP"; 46 | /** 47 | * Constant 48 | */ 49 | static final String SCHEMA_STRATEGY = "schemaStrategy"; 50 | /** 51 | * Constant 52 | */ 53 | static final String DISABLE_ENGLISH_PLURAL = "disableEnglishPlural"; 54 | /** 55 | * Constant 56 | */ 57 | static final String DISABLE_UNDERSCORE_CONVERSION = "disableUnderscoreConversion"; 58 | /** 59 | * Constant 60 | */ 61 | static final String TOP_LEVEL = "topLevel"; 62 | /** 63 | * Constant 64 | */ 65 | static final String DRIVER = "driver"; 66 | /** 67 | * Constant 68 | */ 69 | static final String PROJECT_NAME = "projectName"; 70 | /** 71 | * Constant 72 | */ 73 | static final String SOURCE_TARGET = "sourceTarget"; 74 | /** 75 | * Constant 76 | */ 77 | static final String DATABASE_PASSWORD = "databasePassword"; 78 | /** 79 | * Constant 80 | */ 81 | static final String DATABASE_USERNAME = "databaseUsername"; 82 | /** 83 | * Constant 84 | */ 85 | static final String DATABASE_CATALOG = "databaseCatalog"; 86 | /** 87 | * Constant 88 | */ 89 | static final String DATABASE_SCHEMA = "databaseSchema"; 90 | /** 91 | * Constant 92 | */ 93 | static final String ALL = "ALL"; 94 | /** 95 | * Constant 96 | */ 97 | static final String FULL = "FULL"; 98 | /** 99 | * Constant 100 | */ 101 | static final String PARTIAL = "PARTIAL"; 102 | /** 103 | * Constant 104 | */ 105 | static final String RESTRICT = "RESTRICT"; 106 | /** 107 | * Constant 108 | */ 109 | static final String DATE = "Date"; 110 | /** 111 | * Constant 112 | */ 113 | static final String DATETIME = "DateTime"; 114 | 115 | static final String OFFSETDATETIME = "OffsetDateTime"; 116 | /** 117 | * Constant 118 | */ 119 | static final String LOCALDATE = "LocalDate"; 120 | /** 121 | * Constant 122 | */ 123 | static final String FKTABLE_NAME = "FKTABLE_NAME"; 124 | /** 125 | * Constant 126 | */ 127 | static final String FKTABLE_CAT = "FKTABLE_CAT"; 128 | /** 129 | * Constant 130 | */ 131 | static final String FKCOLUMN_NAME = "FKCOLUMN_NAME"; 132 | /** 133 | * Constant 134 | */ 135 | static final String PKTABLE_CAT = "PKTABLE_CAT"; 136 | /** 137 | * Constant 138 | */ 139 | static final String PKTABLE_SCHEM = "PKTABLE_SCHEM"; 140 | /** 141 | * Constant 142 | */ 143 | static final String FKTABLE_SCHEM = "FKTABLE_SCHEM"; 144 | /** 145 | * Constant 146 | */ 147 | static final String ENUM = "ENUM"; 148 | /** 149 | * Constant 150 | */ 151 | static final String COLUMN_NAME = "COLUMN_NAME"; 152 | /** 153 | * For search/replace 154 | */ 155 | static final String ID = "ID"; 156 | /** 157 | * For search/replace 158 | */ 159 | static final String IDCONST = "_ID"; 160 | 161 | } 162 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/CustomAnnotations.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen; 2 | 3 | import java.io.Serializable; 4 | import java.util.LinkedList; 5 | 6 | /** 7 | * Representation of annotations as read from the config file 8 | * 9 | * @author wallacew 10 | */ 11 | public class CustomAnnotations implements Serializable { 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = -1540962841938250926L; 16 | /** 17 | * annotations to set on property 18 | */ 19 | private LinkedList propertyLevelAnnotations = new LinkedList(); 20 | /** 21 | * annotations to set on getter methods 22 | */ 23 | private LinkedList methodLevelAnnotationsOnGetters = new LinkedList(); 24 | /** 25 | * annotations to set on setter methods 26 | */ 27 | private LinkedList methodLevelAnnotationsOnSetters = new LinkedList(); 28 | /** 29 | * annotations to set on getter methods 30 | */ 31 | private LinkedList methodLevelGetterPrecondition = new LinkedList(); 32 | /** 33 | * annotations to set on setter methods 34 | */ 35 | private LinkedList methodLevelSetterPrecondition = new LinkedList(); 36 | /** 37 | * annotations to set on getter methods 38 | */ 39 | private LinkedList methodLevelGetterPostcondition = new LinkedList(); 40 | /** 41 | * annotations to set on setter methods 42 | */ 43 | private LinkedList methodLevelSetterPostcondition = new LinkedList(); 44 | 45 | /** 46 | * Return a list of property-set annotations 47 | * 48 | * @return the propertyLevelAnnotations 49 | */ 50 | public final LinkedList getPropertyLevelAnnotations() { 51 | return this.propertyLevelAnnotations; 52 | } 53 | 54 | /** 55 | * Sets list of property-set annotations 56 | * 57 | * @param propertyLevelAnnotations the propertyLevelAnnotations to set 58 | */ 59 | public final void setPropertyLevelAnnotations( 60 | LinkedList propertyLevelAnnotations) { 61 | this.propertyLevelAnnotations = propertyLevelAnnotations; 62 | } 63 | 64 | /** 65 | * Returns list of getter method annotations 66 | * 67 | * @return the methodLevelAnnotationsOnGetters 68 | */ 69 | public final LinkedList getMethodLevelAnnotationsOnGetters() { 70 | return this.methodLevelAnnotationsOnGetters; 71 | } 72 | 73 | /** 74 | * Sets list of getter method annotations 75 | * 76 | * @param methodLevelAnnotationsOnGetters the methodLevelAnnotationsOnGetters to set 77 | */ 78 | public final void setMethodLevelAnnotationsOnGetters( 79 | LinkedList methodLevelAnnotationsOnGetters) { 80 | this.methodLevelAnnotationsOnGetters = methodLevelAnnotationsOnGetters; 81 | } 82 | 83 | /** 84 | * Return list of setter method annotations 85 | * 86 | * @return the methodLevelAnnotationsOnSetters 87 | */ 88 | public final LinkedList getMethodLevelAnnotationsOnSetters() { 89 | return this.methodLevelAnnotationsOnSetters; 90 | } 91 | 92 | /** 93 | * Sets list of setter method annotations 94 | * 95 | * @param methodLevelAnnotationsOnSetters the methodLevelAnnotationsOnSetters to set 96 | */ 97 | public final void setMethodLevelAnnotationsOnSetters( 98 | LinkedList methodLevelAnnotationsOnSetters) { 99 | this.methodLevelAnnotationsOnSetters = methodLevelAnnotationsOnSetters; 100 | } 101 | 102 | /** 103 | * @return the methodLevelGetterPrecondition 104 | */ 105 | public final LinkedList getMethodLevelGetterPrecondition() { 106 | return methodLevelGetterPrecondition; 107 | } 108 | 109 | /** 110 | * @param methodLevelGetterPrecondition the methodLevelGetterPrecondition to set 111 | */ 112 | public final void setMethodLevelGetterPrecondition( 113 | LinkedList methodLevelGetterPrecondition) { 114 | this.methodLevelGetterPrecondition = methodLevelGetterPrecondition; 115 | } 116 | 117 | /** 118 | * @return the methodLevelSetterPrecondition 119 | */ 120 | public final LinkedList getMethodLevelSetterPrecondition() { 121 | return methodLevelSetterPrecondition; 122 | } 123 | 124 | /** 125 | * @param methodLevelSetterPrecondition the methodLevelSetterPrecondition to set 126 | */ 127 | public final void setMethodLevelSetterPrecondition( 128 | LinkedList methodLevelSetterPrecondition) { 129 | this.methodLevelSetterPrecondition = methodLevelSetterPrecondition; 130 | } 131 | 132 | /** 133 | * @return the methodLevelGetterPostcondition 134 | */ 135 | public final LinkedList getMethodLevelGetterPostcondition() { 136 | return methodLevelGetterPostcondition; 137 | } 138 | 139 | /** 140 | * @param methodLevelGetterPostcondition the methodLevelGetterPostcondition to set 141 | */ 142 | public final void setMethodLevelGetterPostcondition( 143 | LinkedList methodLevelGetterPostcondition) { 144 | this.methodLevelGetterPostcondition = methodLevelGetterPostcondition; 145 | } 146 | 147 | /** 148 | * @return the methodLevelSetterPostcondition 149 | */ 150 | public final LinkedList getMethodLevelSetterPostcondition() { 151 | return methodLevelSetterPostcondition; 152 | } 153 | 154 | /** 155 | * @param methodLevelSetterPostcondition the methodLevelSetterPostcondition to set 156 | */ 157 | public final void setMethodLevelSetterPostcondition( 158 | LinkedList methodLevelSetterPostcondition) { 159 | this.methodLevelSetterPostcondition = methodLevelSetterPostcondition; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/CustomDB.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen; 2 | 3 | import java.io.Serializable; 4 | import java.util.LinkedList; 5 | 6 | /** 7 | * Used to populate any optional custom insert statements in the DB at some points in DAOTest 8 | * 9 | * @author wallacew 10 | */ 11 | public class CustomDB implements Serializable { 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = -1255063006196789454L; 16 | /** 17 | * The connection url 18 | */ 19 | private String connectionURL; 20 | /** 21 | * The connection username 22 | */ 23 | private String connectionUsername; 24 | /** 25 | * The connection password 26 | */ 27 | private String connectionPassword; 28 | /** 29 | * The driver to use 30 | */ 31 | private String driver; 32 | /** 33 | * The statements to execute 34 | */ 35 | private LinkedList statements; 36 | 37 | /** 38 | * Return the connection URL 39 | * 40 | * @return the connectionURL 41 | */ 42 | public final String getConnectionURL() { 43 | return this.connectionURL; 44 | } 45 | 46 | /** 47 | * Set the connection URL 48 | * 49 | * @param connectionURL the connectionURL to set 50 | */ 51 | public final void setConnectionURL(String connectionURL) { 52 | this.connectionURL = connectionURL; 53 | } 54 | 55 | /** 56 | * Return the connection username 57 | * 58 | * @return the connectionUsername 59 | */ 60 | public final String getConnectionUsername() { 61 | return this.connectionUsername; 62 | } 63 | 64 | /** 65 | * Sets the connection username 66 | * 67 | * @param connectionUsername the connectionUsername to set 68 | */ 69 | public final void setConnectionUsername(String connectionUsername) { 70 | this.connectionUsername = connectionUsername; 71 | } 72 | 73 | /** 74 | * Return the connection password 75 | * 76 | * @return the connectionPassword 77 | */ 78 | public final String getConnectionPassword() { 79 | return this.connectionPassword; 80 | } 81 | 82 | /** 83 | * Sets the connection password 84 | * 85 | * @param connectionPassword the connectionPassword to set 86 | */ 87 | public final void setConnectionPassword(String connectionPassword) { 88 | this.connectionPassword = connectionPassword; 89 | } 90 | 91 | /** 92 | * Return the statements to execute 93 | * 94 | * @return the statements 95 | */ 96 | public final LinkedList getStatements() { 97 | return this.statements; 98 | } 99 | 100 | /** 101 | * Sets the statements to execute 102 | * 103 | * @param statements the statements to set 104 | */ 105 | public final void setStatements(LinkedList statements) { 106 | this.statements = statements; 107 | } 108 | 109 | /** 110 | * Return the driver to use 111 | * 112 | * @return the driver 113 | */ 114 | public final String getDriver() { 115 | return this.driver; 116 | } 117 | 118 | /** 119 | * Sets the driver to use 120 | * 121 | * @param driver the driver to set 122 | */ 123 | public final void setDriver(String driver) { 124 | this.driver = driver; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/EnumMapping.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen; 2 | 3 | import java.io.Serializable; 4 | import java.util.TreeSet; 5 | 6 | 7 | /** 8 | * @author wallacew 9 | * @version $Revision: 3$ 10 | */ 11 | public class EnumMapping implements Serializable { 12 | /** */ 13 | private static final long serialVersionUID = -159650200637534991L; 14 | /** 15 | * Key label column. 16 | */ 17 | private String keyColumnLabel; 18 | /** 19 | * Value label column. 20 | */ 21 | private String valueColumnLabel; 22 | 23 | private String dsttableFieldname; 24 | /** 25 | * Value label column. 26 | */ 27 | private TreeSet otherColumnLabels; 28 | 29 | 30 | /** 31 | * Gets 32 | * 33 | * @return 34 | */ 35 | public TreeSet getOtherColumnLabels() { 36 | return this.otherColumnLabels; 37 | } 38 | 39 | 40 | /** 41 | * Sets 42 | * 43 | * @param otherColumnLabels 44 | */ 45 | public void setOtherColumnLabels(TreeSet otherColumnLabels) { 46 | this.otherColumnLabels = otherColumnLabels; 47 | } 48 | 49 | 50 | /** 51 | * Gets 52 | * 53 | * @return 54 | */ 55 | public String getKeyColumnLabel() { 56 | return this.keyColumnLabel; 57 | } 58 | 59 | 60 | /** 61 | * Sets 62 | * 63 | * @param keyColumnLabel 64 | */ 65 | public void setKeyColumnLabel(String keyColumnLabel) { 66 | this.keyColumnLabel = keyColumnLabel; 67 | } 68 | 69 | 70 | /** 71 | * Gets 72 | * 73 | * @return 74 | */ 75 | public String getValueColumnLabel() { 76 | return this.valueColumnLabel; 77 | } 78 | 79 | 80 | /** 81 | * Sets 82 | * 83 | * @param valueColumnLabel 84 | */ 85 | public void setValueColumnLabel(String valueColumnLabel) { 86 | this.valueColumnLabel = valueColumnLabel; 87 | } 88 | 89 | 90 | /** 91 | * Gets 92 | * 93 | * @return 94 | */ 95 | public String getDsttableFieldname() { 96 | return this.dsttableFieldname; 97 | } 98 | 99 | 100 | /** 101 | * Sets 102 | * 103 | * @param dsttableFieldname 104 | */ 105 | public void setDsttableFieldname(String dsttableFieldname) { 106 | this.dsttableFieldname = dsttableFieldname; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/EnumResult.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen; 2 | 3 | 4 | import java.util.Map; 5 | import java.util.TreeMap; 6 | 7 | 8 | /** 9 | * @author wallacew 10 | * @version $Revision$ 11 | */ 12 | public class EnumResult { 13 | private String[] enumText = {}; 14 | private Map otherColumns = new TreeMap(); 15 | 16 | 17 | /** 18 | * Gets 19 | * 20 | * @return 21 | */ 22 | public String[] getEnumText() { 23 | return this.enumText; 24 | } 25 | 26 | 27 | /** 28 | * Sets 29 | * 30 | * @param enumText 31 | */ 32 | public void setEnumText(String[] enumText) { 33 | this.enumText = enumText; 34 | } 35 | 36 | 37 | /** 38 | * Gets 39 | * 40 | * @return 41 | */ 42 | public Map getOtherColumns() { 43 | return this.otherColumns; 44 | } 45 | 46 | 47 | /** 48 | * Sets 49 | * 50 | * @param otherColumns 51 | */ 52 | public void setOtherColumns(Map otherColumns) { 53 | this.otherColumns = otherColumns; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/FakeFKPattern.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen; 2 | 3 | import java.io.Serializable; 4 | 5 | public class FakeFKPattern implements Serializable { 6 | 7 | /** 8 | * 9 | */ 10 | private static final long serialVersionUID = -1686541777692763787L; 11 | private String pattern; 12 | private String replacePattern; 13 | private boolean enabled; 14 | 15 | public FakeFKPattern(String pattern, String replacePattern, boolean enabled) { 16 | this.pattern = pattern; 17 | this.replacePattern = replacePattern; 18 | this.enabled = enabled; 19 | } 20 | 21 | public String getPattern() { 22 | return pattern; 23 | } 24 | 25 | public void setPattern(String pattern) { 26 | this.pattern = pattern; 27 | } 28 | 29 | public String getReplacePattern() { 30 | return replacePattern; 31 | } 32 | 33 | public void setReplacePattern(String replacePattern) { 34 | this.replacePattern = replacePattern; 35 | } 36 | 37 | public boolean isEnabled() { 38 | return enabled; 39 | } 40 | 41 | public void setEnabled(boolean enabled) { 42 | this.enabled = enabled; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/GeneratedValueFields.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen; 2 | 3 | import com.github.wwadge.hbnpojogen.obj.GeneratorEnum; 4 | 5 | import java.io.Serializable; 6 | import java.util.TreeMap; 7 | 8 | /** 9 | * @author wallacew 10 | */ 11 | public class GeneratedValueFields implements Serializable { 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 5436626887890431955L; 16 | /** 17 | * field 18 | */ 19 | private TreeMap fields = new TreeMap( 20 | new CaseInsensitiveComparator()); 21 | 22 | /** 23 | * Key = field, Value = Generator 24 | * 25 | * @return map 26 | */ 27 | 28 | public TreeMap getFields() { 29 | return fields; 30 | } 31 | 32 | /** 33 | * @param fields 34 | */ 35 | public void setFields(TreeMap fields) { 36 | this.fields = fields; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/GeneratedValueSchemas.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.github.wwadge.hbnpojogen; 5 | 6 | import java.io.Serializable; 7 | import java.util.TreeMap; 8 | 9 | /** 10 | * @author wallacew 11 | */ 12 | public class GeneratedValueSchemas implements Serializable { 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = 3970247201480225514L; 18 | /** 19 | * Key = table, value = Fields 20 | */ 21 | private TreeMap tables = new TreeMap(new CaseInsensitiveComparator()); 22 | 23 | /** 24 | * @return map 25 | */ 26 | public TreeMap getTables() { 27 | return tables; 28 | } 29 | 30 | /** 31 | * @param tables 32 | */ 33 | public void setTables(TreeMap tables) { 34 | this.tables = tables; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/ObjectPair.java: -------------------------------------------------------------------------------- 1 | /** 2 | * A simple key-value pair holder for when TreeMap is not ideal (eg 3 | * LinkedList is required). 4 | */ 5 | package com.github.wwadge.hbnpojogen; 6 | 7 | import java.io.Serializable; 8 | 9 | /** A Simple key-value pair holder of any type. 10 | * @author wallacew 11 | * @param Type to hold as a "key" 12 | * @param Type to hold as a "value" 13 | * 14 | */ 15 | public class ObjectPair implements Serializable, Comparable { 16 | 17 | /** 18 | * Serialization requirement. 19 | */ 20 | private static final long serialVersionUID = -4576578297536905312L; 21 | /** 22 | * Key part of this object. 23 | */ 24 | S key; 25 | /** 26 | * Value part of this object. 27 | */ 28 | T value; 29 | 30 | 31 | /** 32 | * Default Constructor. 33 | * 34 | * @param key Key part. 35 | * @param val Value part 36 | */ 37 | public ObjectPair(S key, T val) { 38 | this.key = key; 39 | this.value = val; 40 | } 41 | 42 | /** 43 | * @return the key 44 | */ 45 | public final S getKey() { 46 | return key; 47 | } 48 | 49 | /** 50 | * @param key the key to set 51 | */ 52 | public final void setKey(S key) { 53 | this.key = key; 54 | } 55 | 56 | /** 57 | * @return the value 58 | */ 59 | public final T getValue() { 60 | return value; 61 | } 62 | 63 | /** 64 | * @param value the value to set 65 | */ 66 | public final void setValue(T value) { 67 | this.value = value; 68 | } 69 | 70 | @Override 71 | public int compareTo(S o) { 72 | return this.compareTo(o); 73 | } 74 | 75 | public String toString() { 76 | return "<" + this.getKey().toString() + ", " + this.getValue().toString() + ">"; 77 | } 78 | 79 | 80 | } 81 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/PackageMap.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.github.wwadge.hbnpojogen; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author wallacew 10 | */ 11 | public class PackageMap implements Serializable { 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 128523304030636399L; 16 | /** 17 | * Inner handle 18 | */ 19 | private String objectPackage; 20 | /** 21 | * Inner handle 22 | */ 23 | private String objectInterfacePackage; 24 | /** 25 | * Inner handle 26 | */ 27 | private String objectTableRepoPackage; 28 | /** 29 | * Inner handle 30 | */ 31 | private String repositoryFactoryPackage; 32 | /** 33 | * Inner handle 34 | */ 35 | private String daoPackage; 36 | /** 37 | * Inner handle 38 | */ 39 | private String daoImplPackage; 40 | /** 41 | * Inner handle 42 | */ 43 | private String enumPackage; 44 | /** 45 | * Inner handle 46 | */ 47 | private String enumPackageTargetBase; 48 | /** 49 | * Inner handle 50 | */ 51 | private String enumSubtypePackage; 52 | /** 53 | * Inner handle 54 | */ 55 | private String factoryPackage; 56 | /** 57 | * Inner handle 58 | */ 59 | private String utilPackage; 60 | /** 61 | * Inner handle 62 | */ 63 | private String dataPackage; 64 | 65 | /** 66 | * Object package. 67 | * 68 | * @return object package name 69 | */ 70 | public String getObjectPackage() { 71 | return this.objectPackage; 72 | } 73 | 74 | /** 75 | * @param objectPackage 76 | */ 77 | public void setObjectPackage(String objectPackage) { 78 | this.objectPackage = objectPackage; 79 | } 80 | 81 | /** 82 | * @return dao package 83 | */ 84 | public String getDaoPackage() { 85 | return this.daoPackage; 86 | } 87 | 88 | /** 89 | * @param daoPackage 90 | */ 91 | public void setDaoPackage(String daoPackage) { 92 | this.daoPackage = daoPackage; 93 | } 94 | 95 | /** 96 | * @return enum package 97 | */ 98 | public String getEnumPackage() { 99 | return this.enumPackage; 100 | } 101 | 102 | /** 103 | * @param enumPackage 104 | */ 105 | public void setEnumPackage(String enumPackage) { 106 | this.enumPackage = enumPackage; 107 | } 108 | 109 | /** 110 | * @return factory package 111 | */ 112 | public String getFactoryPackage() { 113 | return this.factoryPackage; 114 | } 115 | 116 | /** 117 | * @param factoryPackage 118 | */ 119 | public void setFactoryPackage(String factoryPackage) { 120 | this.factoryPackage = factoryPackage; 121 | } 122 | 123 | /** 124 | * @return data package 125 | */ 126 | public String getDataPackage() { 127 | return this.dataPackage; 128 | } 129 | 130 | /** 131 | * @param dataPackage 132 | */ 133 | public void setDataPackage(String dataPackage) { 134 | this.dataPackage = dataPackage; 135 | } 136 | 137 | /** 138 | * @return daoimpl 139 | */ 140 | public String getDaoImplPackage() { 141 | return this.daoImplPackage; 142 | } 143 | 144 | /** 145 | * @param daoImplPackage 146 | */ 147 | public void setDaoImplPackage(String daoImplPackage) { 148 | this.daoImplPackage = daoImplPackage; 149 | } 150 | 151 | /** 152 | * @return the objectInterfacePackage 153 | */ 154 | public final String getObjectInterfacePackage() { 155 | return this.objectInterfacePackage; 156 | } 157 | 158 | /** 159 | * @param objectInterfacePackage the objectInterfacePackage to set 160 | */ 161 | public final void setObjectInterfacePackage(String objectInterfacePackage) { 162 | this.objectInterfacePackage = objectInterfacePackage; 163 | } 164 | 165 | 166 | /** 167 | * Gets enum subtype package 168 | * 169 | * @return enum subtype packge 170 | */ 171 | public String getEnumSubtypePackage() { 172 | return this.enumSubtypePackage; 173 | } 174 | 175 | 176 | /** 177 | * Sets enum subtype package. 178 | * 179 | * @param enumSubtypePackage 180 | */ 181 | public void setEnumSubtypePackage(String enumSubtypePackage) { 182 | this.enumSubtypePackage = enumSubtypePackage; 183 | } 184 | 185 | /** 186 | * @return the objectTableRepoPackage 187 | */ 188 | public String getObjectTableRepoPackage() { 189 | return objectTableRepoPackage; 190 | } 191 | 192 | /** 193 | * @param objectTableRepoPackage the objectTableRepoPackage to set 194 | */ 195 | public void setObjectTableRepoPackage(String objectTableRepoPackage) { 196 | this.objectTableRepoPackage = objectTableRepoPackage; 197 | } 198 | 199 | /** 200 | * @return the utilPackage 201 | */ 202 | public String getUtilPackage() { 203 | return utilPackage; 204 | } 205 | 206 | /** 207 | * @param utilPackage the utilPackage to set 208 | */ 209 | public void setUtilPackage(String utilPackage) { 210 | this.utilPackage = utilPackage; 211 | } 212 | 213 | /** 214 | * @return the repositoryFactoryPackage 215 | */ 216 | public String getRepositoryFactoryPackage() { 217 | return repositoryFactoryPackage; 218 | } 219 | 220 | /** 221 | * @param repositoryFactoryPackage the repositoryFactoryPackage to set 222 | */ 223 | public void setRepositoryFactoryPackage(String repositoryFactoryPackage) { 224 | this.repositoryFactoryPackage = repositoryFactoryPackage; 225 | } 226 | 227 | /** 228 | * @return the enumPackageTargetBase 229 | */ 230 | public String getEnumPackageTargetBase() { 231 | return enumPackageTargetBase; 232 | } 233 | 234 | /** 235 | * @param enumPackageTargetBase the enumPackageTargetBase to set 236 | */ 237 | public void setEnumPackageTargetBase(String enumPackageTargetBase) { 238 | this.enumPackageTargetBase = enumPackageTargetBase; 239 | } 240 | 241 | } 242 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/PackageTypeEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Just an enum. 3 | */ 4 | package com.github.wwadge.hbnpojogen; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author wallacew 10 | */ 11 | public enum PackageTypeEnum implements Serializable { 12 | /** 13 | * Constant. 14 | */ 15 | OBJECT, 16 | /** 17 | * Constant. 18 | */ 19 | OBJECTINTERFACE, 20 | /** 21 | * Constant. 22 | */ 23 | TABLE_REPO, 24 | /** 25 | * Constant. 26 | */ 27 | TABLE_REPO_FACTORY, 28 | 29 | /** 30 | * Constant. 31 | */ 32 | DAO, 33 | /** 34 | * Constant. 35 | */ 36 | ENUM, 37 | /** 38 | * Constant. 39 | */ 40 | SUBTYPE_ENUM, 41 | /** 42 | * Constant. 43 | */ 44 | FACTORY, 45 | /** 46 | * Constant. 47 | */ 48 | DATA, 49 | UTIL, 50 | /** 51 | * Constant. 52 | */ 53 | DAOIMPL, 54 | ENUM_TARGET_BASE, 55 | OPENAPI_SCHEMA; 56 | } 57 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/RelationItem.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen; 2 | 3 | public class RelationItem { 4 | private String catalog; 5 | private String schema; 6 | private String fkSchema; 7 | private String tableName; 8 | private String fkTableName; 9 | private String fkCatalog; 10 | private String fkName; 11 | private String fkColumnName; 12 | private String pkColumnName; 13 | private Integer keySeq; 14 | 15 | public String getFkName() { 16 | return fkName; 17 | } 18 | 19 | public void setFkName(String fkName) { 20 | this.fkName = fkName; 21 | } 22 | 23 | public String getPkColumnName() { 24 | return pkColumnName; 25 | } 26 | 27 | public void setPkColumnName(String pkColumnName) { 28 | this.pkColumnName = pkColumnName; 29 | } 30 | 31 | public Integer getKeySeq() { 32 | return keySeq; 33 | } 34 | 35 | public void setKeySeq(Integer keySeq) { 36 | this.keySeq = keySeq; 37 | } 38 | 39 | public String getCatalog() { 40 | return catalog; 41 | } 42 | 43 | public void setCatalog(String catalog) { 44 | this.catalog = catalog; 45 | } 46 | 47 | public String getTableName() { 48 | return tableName; 49 | } 50 | 51 | public void setTableName(String tableName) { 52 | this.tableName = tableName; 53 | } 54 | 55 | public String getFkColumnName() { 56 | return fkColumnName; 57 | } 58 | 59 | public void setFkColumnName(String fkColumnName) { 60 | this.fkColumnName = fkColumnName; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "Catalog = " + catalog + ", tableName = " + tableName + ", fkColumnName = " + fkColumnName + ", FK table: " + this.fkTableName; 66 | } 67 | 68 | @Override 69 | public boolean equals(Object obj) { 70 | if (!(obj instanceof RelationItem)) { 71 | return false; 72 | } 73 | 74 | RelationItem rel = (RelationItem) obj; 75 | 76 | return rel != null 77 | && rel.catalog.equals(this.catalog) 78 | && rel.schema.equals(this.schema) 79 | && rel.fkSchema.equals(this.fkSchema) 80 | && rel.fkName.equals(this.fkName) 81 | && rel.fkTableName.equals(this.fkTableName) 82 | && rel.tableName.equals(this.tableName) 83 | && rel.fkColumnName.equals(this.fkColumnName) 84 | && rel.pkColumnName.equals(this.pkColumnName) 85 | && rel.fkCatalog.equals(this.fkCatalog) 86 | && rel.keySeq.equals(this.keySeq); 87 | 88 | 89 | } 90 | 91 | public String getFkTableName() { 92 | return fkTableName; 93 | } 94 | 95 | public void setFkTableName(String fkTableName) { 96 | this.fkTableName = fkTableName; 97 | } 98 | 99 | public String getFkCatalog() { 100 | return fkCatalog; 101 | } 102 | 103 | public void setFkCatalog(String fkCatalog) { 104 | this.fkCatalog = fkCatalog; 105 | } 106 | 107 | /** 108 | * @return the schema 109 | */ 110 | public String getSchema() { 111 | return schema; 112 | } 113 | 114 | /** 115 | * @param schema the schema to set 116 | */ 117 | public void setSchema(String schema) { 118 | this.schema = schema; 119 | } 120 | 121 | /** 122 | * @return the fkSchema 123 | */ 124 | public String getFkSchema() { 125 | return fkSchema; 126 | } 127 | 128 | /** 129 | * @param fkSchema the fkSchema to set 130 | */ 131 | public void setFkSchema(String fkSchema) { 132 | this.fkSchema = fkSchema; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/VelocityTable.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen; 2 | 3 | import com.github.wwadge.hbnpojogen.db.TableObj; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * just a hack to get commit order right when writing unit tests 9 | * 10 | * @author wallacew 11 | */ 12 | public class VelocityTable implements Serializable, Comparable { 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 5678910761714392893L; 17 | /** 18 | * For commit order 19 | */ 20 | private String key; 21 | /** 22 | * For commit order 23 | */ 24 | private TableObj value; 25 | 26 | /** 27 | * Getter key 28 | * 29 | * @return this.key 30 | */ 31 | public String getKey() { 32 | return this.key; 33 | } 34 | 35 | /** 36 | * Setter for key 37 | * 38 | * @param key 39 | */ 40 | public void setKey(String key) { 41 | this.key = key; 42 | } 43 | 44 | /** 45 | * Return table object 46 | * 47 | * @return this.value 48 | */ 49 | public TableObj getValue() { 50 | return this.value; 51 | } 52 | 53 | /** 54 | * Setter table object 55 | * 56 | * @param value 57 | */ 58 | public void setValue(TableObj value) { 59 | this.value = value; 60 | } 61 | 62 | @Override 63 | public int compareTo(VelocityTable o) { 64 | return this.key.compareTo(o.getKey()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/db/KeyObj.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen.db; 2 | 3 | import com.github.wwadge.hbnpojogen.CaseInsensitiveComparator; 4 | 5 | import java.io.Serializable; 6 | import java.util.TreeMap; 7 | 8 | /** 9 | * Imported/Exported keys representation 10 | * 11 | * @author wallacew 12 | */ 13 | public class KeyObj implements Serializable { 14 | 15 | /** 16 | * 17 | */ 18 | private static final long serialVersionUID = -5994093176012581240L; 19 | /** 20 | * pk table name 21 | */ 22 | private String pkTableName; 23 | private String pkTableSchema; 24 | /** 25 | * pk table catalog 26 | */ 27 | private String pkTableCatalog; 28 | /** 29 | * for exported keys. 30 | */ 31 | private String field; 32 | 33 | /** 34 | * Key = pkColName, Value = fkColName 35 | */ 36 | private TreeMap keyLinks = new TreeMap( 37 | new CaseInsensitiveComparator()); 38 | 39 | /* (non-Javadoc) 40 | * @see java.lang.Object#toString() 41 | */ 42 | @Override 43 | public String toString() { 44 | return this.pkTableCatalog + "." + this.pkTableSchema + "." + this.pkTableName + ", keyLinks=" 45 | + this.keyLinks.toString(); 46 | } 47 | 48 | /** 49 | * Constructor 50 | * 51 | * @param fkColName 52 | * @param pkTableName 53 | * @param pkTableCatalog 54 | * @param pkColName 55 | */ 56 | public KeyObj(String fkColName, String pkTableName, String pkTableCatalog, String pkTableSchema, 57 | String pkColName) { 58 | 59 | this.pkTableName = pkTableName; 60 | this.pkTableSchema = pkTableSchema; 61 | this.pkTableCatalog = pkTableCatalog; 62 | this.keyLinks.put(fkColName, pkColName); 63 | } 64 | 65 | /** 66 | * Constructor for exported keys. 67 | * 68 | * @param pkTableName 69 | * @param field 70 | */ 71 | public KeyObj(String pkTableName, String field) { 72 | 73 | this.pkTableName = pkTableName; 74 | this.field = field; 75 | } 76 | 77 | /** 78 | * Convenience function 79 | * 80 | * @return true if the key is a composite key 81 | */ 82 | public boolean isCompositeKey() { 83 | return this.keyLinks.size() > 1; 84 | } 85 | 86 | /** 87 | * Convenience function 88 | * 89 | * @return pkTablecatalog + "." + pkTableName 90 | */ 91 | public String getPKFullTableName() { 92 | return this.pkTableCatalog + "." + (this.pkTableSchema == null ? "" : this.pkTableSchema + ".") + this.pkTableName; 93 | } 94 | 95 | /** 96 | * Return PK Table name 97 | * 98 | * @return pk table name 99 | */ 100 | public String getPkTableName() { 101 | return this.pkTableName; 102 | } 103 | 104 | /** 105 | * Set the PK Table name 106 | * 107 | * @param name 108 | */ 109 | public void setPkTableName(String name) { 110 | this.pkTableName = name; 111 | } 112 | 113 | /** 114 | * Returns the db catalog 115 | * 116 | * @return The db catalog 117 | */ 118 | public String getPkTableCatalog() { 119 | return this.pkTableCatalog; 120 | } 121 | 122 | /** 123 | * Sets the db catalog 124 | * 125 | * @param pkTableCatalog 126 | */ 127 | public void setPkTableCatalog(String pkTableCatalog) { 128 | this.pkTableCatalog = pkTableCatalog; 129 | } 130 | 131 | /** 132 | * Return the keyLinks 133 | * 134 | * @return the keyLinks 135 | */ 136 | public final TreeMap getKeyLinks() { 137 | return this.keyLinks; 138 | } 139 | 140 | /** 141 | * Sets the keyLinks 142 | * 143 | * @param keyLinks the keyLinks to set 144 | */ 145 | public final void setKeyLinks(TreeMap keyLinks) { 146 | this.keyLinks = keyLinks; 147 | } 148 | 149 | /** 150 | * @return the field 151 | */ 152 | public final String getField() { 153 | return this.field; 154 | } 155 | 156 | /** 157 | * @param field the field to set 158 | */ 159 | public final void setField(String field) { 160 | this.field = field; 161 | } 162 | 163 | } 164 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/obj/GeneratorEnum.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen.obj; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Generator Enum. 7 | * 8 | * @author wallacew 9 | */ 10 | public enum GeneratorEnum implements Serializable { 11 | /** 12 | * Constant 13 | */ 14 | AUTO, 15 | /** 16 | * Constant 17 | */ 18 | UUID, 19 | /** 20 | * Constant 21 | */ 22 | UUIDWithoutDashes, 23 | /** 24 | * Constant 25 | */ 26 | GUID, 27 | /** 28 | * Constant 29 | */ 30 | NONE, 31 | /** 32 | * Constant. 33 | */ 34 | CUSTOM, 35 | /** 36 | * Constant. 37 | */ 38 | PKS, 39 | IDENTITY, 40 | SEQUENCE, 41 | /** 42 | * Constant. 43 | */ 44 | IDAWARE 45 | } 46 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/obj/JoinTable.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen.obj; 2 | 3 | import java.io.Serializable; 4 | 5 | 6 | /** 7 | * Helper class to handle join tables 8 | * 9 | * @author wallacew 10 | */ 11 | public class JoinTable implements Comparable, Serializable { 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = -342066601575899425L; 16 | /** 17 | * Join link should bounce off this class 18 | */ 19 | private Clazz linkClass; 20 | /** 21 | * The source leg of this link 22 | */ 23 | private PropertyObj srcProperty; 24 | /** 25 | * The destination leg of this link 26 | */ 27 | private PropertyObj dstProperty; 28 | /** 29 | * when bouncing off a map, this is the src property on the map side. 30 | */ 31 | private PropertyObj srcPropertyBounce; 32 | /** 33 | * when bouncing off a map, this is the property on the map side. 34 | */ 35 | private PropertyObj dstPropertyBounce; 36 | 37 | 38 | /* (non-Javadoc) 39 | * @see java.lang.Object#toString() 40 | */ 41 | @Override 42 | public String toString() { 43 | return "linkClass = " + this.linkClass.toString() + ", srcProperty = " 44 | + this.srcProperty.toString() + ", dstProperty = " + this.dstProperty.toString(); 45 | } 46 | 47 | /** 48 | * Constructor 49 | * 50 | * @param srcProperty 51 | * @param dstProperty 52 | * @param linkClass 53 | */ 54 | public JoinTable(final PropertyObj srcProperty, final PropertyObj dstProperty, Clazz linkClass) { 55 | this.srcProperty = srcProperty; 56 | this.dstProperty = dstProperty; 57 | this.linkClass = linkClass; 58 | } 59 | 60 | /** 61 | * Returns the linked class 62 | * 63 | * @return the linkClass 64 | */ 65 | public final Clazz getLinkClass() { 66 | return this.linkClass; 67 | } 68 | 69 | /** 70 | * Sets the linked class 71 | * 72 | * @param linkClass the linkClass to set 73 | */ 74 | public final void setLinkClass(Clazz linkClass) { 75 | this.linkClass = linkClass; 76 | } 77 | 78 | /** 79 | * Return the source property object on the source join 80 | * 81 | * @return the srcProperty 82 | */ 83 | public final PropertyObj getSrcProperty() { 84 | return this.srcProperty; 85 | } 86 | 87 | /** 88 | * Sets the source property object on the source join 89 | * 90 | * @param srcProperty the srcProperty to set 91 | */ 92 | public final void setSrcProperty(PropertyObj srcProperty) { 93 | this.srcProperty = srcProperty; 94 | } 95 | 96 | /** 97 | * Gets the destination property object on the destination of the join 98 | * 99 | * @return the destPropery 100 | */ 101 | public final PropertyObj getDstProperty() { 102 | return this.dstProperty; 103 | } 104 | 105 | /** 106 | * Sets the destination property object on the destination of the join 107 | * 108 | * @param destPropery the destPropery to set 109 | */ 110 | public final void setDstProperty(PropertyObj destPropery) { 111 | this.dstProperty = destPropery; 112 | } 113 | 114 | @Override 115 | public int compareTo(JoinTable o) { 116 | 117 | return o.getLinkClass().getClassName().compareTo(this.getLinkClass().getClassName()); 118 | } 119 | 120 | /** 121 | * @return the srcPropertyBounce 122 | */ 123 | public PropertyObj getSrcPropertyBounce() { 124 | return this.srcPropertyBounce; 125 | } 126 | 127 | /** 128 | * @param srcPropertyBounce the srcPropertyBounce to set 129 | */ 130 | public void setSrcPropertyBounce(PropertyObj srcPropertyBounce) { 131 | this.srcPropertyBounce = srcPropertyBounce; 132 | } 133 | 134 | /** 135 | * @return the dstPropertyBounce 136 | */ 137 | public PropertyObj getDstPropertyBounce() { 138 | return this.dstPropertyBounce; 139 | } 140 | 141 | /** 142 | * @param dstPropertyBounce the dstPropertyBounce to set 143 | */ 144 | public void setDstPropertyBounce(PropertyObj dstPropertyBounce) { 145 | this.dstPropertyBounce = dstPropertyBounce; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/java/com/github/wwadge/hbnpojogen/obj/PropertyMeta.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen.obj; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Defines the type of the property 7 | * 8 | * @author wallacew 9 | */ 10 | public enum PropertyMeta implements Serializable { 11 | /** 12 | * Property Type 13 | */ 14 | NORMAL_FIELD, 15 | /** 16 | * Property Type 17 | */ 18 | ENUM_FIELD, 19 | /** 20 | * Property Type 21 | */ 22 | MANY_TO_ONE_FIELD, 23 | /** 24 | * Property Type 25 | */ 26 | PRIMARY_FIELD, 27 | /** 28 | * Property Type 29 | */ 30 | PRIMARY_FOREIGN_KEY, 31 | /** 32 | * Property Type 33 | */ 34 | COMPOSITE_MANY_TO_ONE, 35 | /** 36 | * Property Type 37 | */ 38 | ONE_TO_ONE_FIELD 39 | } 40 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This defines the logging level for the rootLogger. It is not required 3 | # if you are going to keep the level at debug as the rootLogger by default 4 | # is at the debug level. The value after the comma is the appender for the 5 | # root and we have given it the name R 6 | # 7 | log4j.rootLogger=ERROR, Console 8 | 9 | 10 | # When logging using the ConsoleAppender, the following value tells how and 11 | # what to log. The SimpleLayout simply logs the level of the message and 12 | # the message itself. 13 | # 14 | log4j.appender.DBSync.layout=org.apache.log4j.PatternLayout 15 | 16 | log4j.appender.org.apache.commons.configuration=org.apache.log4j.ConsoleAppender 17 | log4j.appender.org.apache.commons.configuration.Threshold=ERROR 18 | 19 | log4j.appender.Console=org.apache.log4j.ConsoleAppender 20 | log4j.appender.Console.layout=org.apache.log4j.PatternLayout 21 | log4j.appender.Console.layout.ConversionPattern=%p %d{ISO8601} %C %m %n 22 | log4j.appender.Console.Threshold=debug 23 | 24 | org.apache.velocity.runtime.log.JdkLogChute=ERROR -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/synchronizer.version: -------------------------------------------------------------------------------- 1 | ${project.version} -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/CustomRepository.vm: -------------------------------------------------------------------------------- 1 | package ${packagename}; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.data.repository.NoRepositoryBean; 7 | 8 | /** 9 | * Extends the jpa repo to teach it about hibernate's getReference method. 10 | * @author autogenerated 11 | * @param 12 | * @param 13 | * 14 | */ 15 | @NoRepositoryBean 16 | public interface CustomRepository extends JpaRepository { 17 | 18 | /** Returns a proxy to the given ID, does not hit DB 19 | * @param primaryKey ID to return a proxy to 20 | * @return A proxy to the class */ 21 | T getReference(ID primaryKey); 22 | 23 | /** 24 | * Merge the state of the given entity into the 25 | * current persistence context. 26 | * @param entity entity instance 27 | * @return the managed instance that the state was merged to 28 | * @throws IllegalArgumentException if instance is not an 29 | * entity or is a removed entity 30 | * @throws jakarta.persistence.TransactionRequiredException if invoked on a 31 | * container-managed entity manager of type 32 | * PersistenceContextType.TRANSACTION and there is 33 | * no transaction 34 | */ 35 | T merge(T entity); 36 | 37 | /** 38 | * Merge the state of the given entity into the 39 | * current persistence context. 40 | * @param entity entity instance 41 | * @return the managed instance that the state was merged to 42 | * @throws IllegalArgumentException if instance is not an 43 | * entity or is a removed entity 44 | * @throws TransactionRequiredException if invoked on a 45 | * container-managed entity manager of type 46 | * PersistenceContextType.TRANSACTION and there is 47 | * no transaction 48 | */ 49 | void refresh(T entity); 50 | } 51 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/CustomRepositoryImpl.vm: -------------------------------------------------------------------------------- 1 | 2 | package ${packagename}; 3 | 4 | import java.io.Serializable; 5 | 6 | import jakarta.persistence.EntityManager; 7 | 8 | import org.springframework.data.jpa.repository.support.JpaEntityInformation; 9 | import org.springframework.data.jpa.repository.support.QuerydslJpaRepository; 10 | import java.io.Serializable; 11 | 12 | import ${packagename}.CustomRepository; 13 | 14 | /** 15 | * Extends the usual repo methods with custom methods. 16 | * @author autogenerated 17 | * @param 18 | * @param 19 | * 20 | */ 21 | 22 | public class CustomRepositoryImpl extends QuerydslJpaRepository implements CustomRepository { 23 | 24 | /** Hold a reference to the entity manager, hibernate for eg */ 25 | private EntityManager entityManager; 26 | /** Store a reference to the domain class here to be used for some of the methods. */ 27 | private Class entityClass; 28 | 29 | /** 30 | * @param entityInformation 31 | * @param entityManager 32 | */ 33 | public CustomRepositoryImpl(JpaEntityInformation entityInformation, 34 | EntityManager entityManager) { 35 | super(entityInformation, entityManager); 36 | this.entityManager = entityManager; 37 | this.entityClass = entityInformation.getJavaType(); 38 | } 39 | 40 | @Override 41 | public T getReference(ID primaryKey) { 42 | return entityManager.getReference(entityClass, primaryKey); 43 | } 44 | 45 | 46 | 47 | @Override 48 | public T merge(T entity){ 49 | return entityManager.merge(entity); 50 | } 51 | 52 | @Override 53 | public void refresh(T entity){ 54 | entityManager.refresh(entity); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/IPojoGenEntity.vm: -------------------------------------------------------------------------------- 1 | package ${packagename}; 2 | 3 | 4 | import java.io.Serializable; 5 | 6 | 7 | 8 | /** 9 | * All generated model classes implement this interface. 10 | * 11 | * @author autogenerated 12 | */ 13 | public interface IPojoGenEntity { 14 | 15 | /** Return the type of this class. Useful for when dealing with proxies. 16 | * @return Defining class. 17 | */ 18 | Class getClassType(); 19 | 20 | /** 21 | * Return the id. 22 | * 23 | * @return the id. 24 | */ 25 | Serializable getId(); 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/MockDatabase.vm: -------------------------------------------------------------------------------- 1 | package ${packagename}; 2 | 3 | 4 | import ${repositoryClass}; 5 | import com.google.common.collect.Lists; 6 | import com.google.common.collect.Maps; 7 | 8 | import org.mockito.Mockito; 9 | import org.mockito.invocation.InvocationOnMock; 10 | import org.mockito.stubbing.Answer; 11 | import org.springframework.core.annotation.AnnotationUtils; 12 | import org.springframework.test.util.ReflectionTestUtils; 13 | 14 | import jakarta.persistence.Basic; 15 | import javax.validation.ConstraintViolation; 16 | import javax.validation.Validator; 17 | import java.io.Serializable; 18 | import java.lang.annotation.Annotation; 19 | import java.lang.reflect.Method; 20 | import java.util.List; 21 | import java.util.Map; 22 | import java.util.Random; 23 | import java.util.Set; 24 | 25 | import static org.mockito.Matchers.anyObject; 26 | import static org.mockito.Mockito.*; 27 | 28 | /** 29 | * Helper class for use in tests to fake the existence of a database. 30 | * 31 | * @author autogenerated 32 | */ 33 | public class MockDatabase { 34 | 35 | protected Map fakeDatabase = Maps.newHashMap(); 36 | 37 | private final CustomRepository repository; 38 | 39 | private Validator validator; 40 | 41 | public void setValidator(Validator validator) { 42 | this.validator = validator; 43 | } 44 | 45 | public static T mock(Class classToMock, Validator validator) { 46 | 47 | T repository = Mockito.mock(classToMock); 48 | MockDatabase md = new MockDatabase(repository, validator); 49 | 50 | return repository; 51 | } 52 | 53 | 54 | public MockDatabase(CustomRepository repository, Validator validator){ 55 | this.repository = (CustomRepository) repository; 56 | this.validator = validator; 57 | 58 | 59 | reset(repository); 60 | doAnswer(new Answer() { 61 | @Override 62 | public Object answer(InvocationOnMock invocation) throws Throwable { 63 | fakeDatabase.clear(); 64 | return null; 65 | } 66 | }).when(repository).deleteAll(); 67 | 68 | when(repository.save((T) anyObject())).thenAnswer(new Answer() { 69 | @Override 70 | public T answer(InvocationOnMock invocation) throws Throwable { 71 | return saveOrSaveAndFlush(invocation); 72 | } 73 | }); 74 | 75 | 76 | when(repository.getReference((ID)anyObject())).thenAnswer(new Answer() { 77 | @Override 78 | public T answer(InvocationOnMock invocation) throws Throwable { 79 | return fakeDatabase.get(invocation.getArguments()[0]); 80 | } 81 | }); 82 | 83 | when(repository.findOne((ID)anyObject())).thenAnswer(new Answer() { 84 | @Override 85 | public T answer(InvocationOnMock invocation) throws Throwable { 86 | return fakeDatabase.get(invocation.getArguments()[0]); 87 | } 88 | }); 89 | 90 | doAnswer(new Answer() { 91 | @Override 92 | public T answer(InvocationOnMock invocation) throws Throwable { 93 | return fakeDatabase.remove(ReflectionTestUtils.invokeGetterMethod(invocation.getArguments()[0], "getId")); 94 | } 95 | }).when(repository).delete((T)anyObject()); 96 | 97 | 98 | doAnswer(new Answer() { 99 | @Override 100 | public ID answer(InvocationOnMock invocation) throws Throwable { 101 | fakeDatabase.remove(((ID)invocation.getArguments()[0])); 102 | return null; 103 | } 104 | }).when(repository).delete((ID)anyObject()); 105 | 106 | 107 | when(repository.saveAndFlush((T) anyObject())).thenAnswer(new Answer() { 108 | @Override 109 | public T answer(InvocationOnMock invocation) throws Throwable { 110 | return saveOrSaveAndFlush(invocation); 111 | } 112 | 113 | 114 | }); 115 | 116 | when(repository.exists((ID)anyObject())).thenAnswer(new Answer() { 117 | @Override 118 | public Boolean answer(InvocationOnMock invocation) throws Throwable { 119 | return fakeDatabase.containsKey(invocation.getArguments()[0]); 120 | } 121 | }); 122 | 123 | 124 | when(repository.merge(anyObject())).thenAnswer(new Answer() { 125 | @Override 126 | public T answer(InvocationOnMock invocation) throws Throwable { 127 | return (T) invocation.getArguments()[0]; 128 | } 129 | }); 130 | 131 | 132 | when(repository.findAll()).thenAnswer(new Answer>() { 133 | @Override 134 | public List answer(InvocationOnMock invocation) throws Throwable { 135 | return Lists.newLinkedList(fakeDatabase.values()); 136 | } 137 | }); 138 | 139 | customMethods(); 140 | 141 | } 142 | 143 | private T saveOrSaveAndFlush(InvocationOnMock invocation) throws NoSuchMethodException { 144 | Object[] args = invocation.getArguments(); 145 | Serializable id = (Serializable) ReflectionTestUtils.getField(args[0], "id"); 146 | if (id == null) { 147 | Class returnType = args[0].getClass().getMethod("getId").getReturnType(); 148 | 149 | if (returnType.equals(Long.class)) { 150 | id = (Long) new Random().nextLong(); 151 | } else if (returnType.equals(Integer.class)) { 152 | id = (Integer) new Random().nextInt(); 153 | } 154 | ReflectionTestUtils.setField(args[0], "id", id); 155 | } 156 | 157 | Set> validations = validator.validate((T)args[0]); 158 | if (!validations.isEmpty()){ 159 | throw new IllegalStateException("Object failed validations (it would also fail on a db): "+validations); 160 | } 161 | for (Method method: args[0].getClass().getDeclaredMethods()){ 162 | if (method.isAnnotationPresent(Basic.class)){ 163 | Annotation a = method.getAnnotation(Basic.class); 164 | if (!(boolean) AnnotationUtils.getValue(method.getAnnotation(Basic.class), "optional")){ 165 | if (ReflectionTestUtils.invokeGetterMethod(args[0], method.getName()) == null){ 166 | throw new IllegalStateException(args[0].getClass().getSimpleName()+"."+method.getName() + " returned null, but marked with @Basic(optional=false) - it would also fail on a db: "+validations); 167 | 168 | } 169 | } 170 | } 171 | } 172 | fakeDatabase.put(id, (T) args[0]); 173 | 174 | return (T) args[0]; 175 | } 176 | 177 | public void customMethods() { 178 | // override here if you want 179 | } 180 | 181 | } 182 | 183 | 184 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/RepositoryFactoryBean.vm: -------------------------------------------------------------------------------- 1 | package ${packagename}; 2 | 3 | import java.io.Serializable; 4 | 5 | import jakarta.persistence.EntityManager; 6 | 7 | import org.springframework.data.jpa.repository.JpaRepository; 8 | import org.springframework.data.jpa.repository.support.JpaEntityInformation; 9 | import org.springframework.data.jpa.repository.support.JpaRepositoryFactory; 10 | import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean; 11 | import org.springframework.data.repository.core.RepositoryMetadata; 12 | import org.springframework.data.repository.core.support.RepositoryFactorySupport; 13 | 14 | import ${packagename}.CustomRepositoryImpl; 15 | 16 | /** 17 | * As copied from the spring docs. This will make spring call our custom repo implementation 18 | * rather than returning the default SimpleRepo. We do this to make it possible to call 19 | * additional methods defined in CustomRepository{Impl}. 20 | * 21 | * @author autogenerated 22 | * @param 23 | * @param 24 | * @param 25 | * 26 | */ 27 | public class RepositoryFactoryBean , T, I extends Serializable> 28 | extends JpaRepositoryFactoryBean { 29 | 30 | /** 31 | * Creates a new {@link JpaRepositoryFactoryBean} for the given repository interface. 32 | * 33 | * @param repositoryInterface must not be {@literal null}. 34 | */ 35 | public RepositoryFactoryBean(Class repositoryInterface) { 36 | super(repositoryInterface); 37 | } 38 | 39 | 40 | protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) { 41 | return new CustomRepositoryFactory(entityManager); 42 | } 43 | 44 | /** Internal class to make Spring data magic work. 45 | * @author wwadge 46 | * 47 | * @param 48 | * @param 49 | */ 50 | private static class CustomRepositoryFactory extends JpaRepositoryFactory { 51 | 52 | /** Reference to the entity manager. */ 53 | private EntityManager entityManager; 54 | 55 | /** Default constructor. 56 | * @param entityManager 57 | */ 58 | public CustomRepositoryFactory(EntityManager entityManager) { 59 | super(entityManager); 60 | this.entityManager = entityManager; 61 | } 62 | 63 | 64 | @SuppressWarnings({ "rawtypes", "unchecked" }) 65 | protected Object getTargetRepository(RepositoryMetadata metadata) { 66 | 67 | JpaEntityInformation entityInformation = 68 | getEntityInformation(metadata.getDomainType()); 69 | 70 | return new CustomRepositoryImpl(entityInformation, entityManager); //custom implementation 71 | 72 | 73 | } 74 | 75 | protected Class getRepositoryBaseClass(RepositoryMetadata metadata) { 76 | return CustomRepositoryImpl.class; 77 | } 78 | 79 | } 80 | } -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/StringValuedEnum.vm: -------------------------------------------------------------------------------- 1 | package ${packagename}; 2 | /** 3 | * Utility class designed to allow dynamic fiddling and manipulation of Enum 4 | * instances which hold a string value. 5 | * @author autogenerated 6 | */ 7 | public interface StringValuedEnum { 8 | 9 | /** 10 | * Current string value stored in the enum. 11 | * @return string value. 12 | */ 13 | String getValue(); 14 | 15 | } -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/StringValuedEnumReflect.vm: -------------------------------------------------------------------------------- 1 | 2 | package ${packagename}; 3 | import java.lang.reflect.InvocationTargetException; 4 | 5 | /** 6 | * Utility class designed to inspect StringValuedEnums. 7 | * @author autogenerated 8 | */ 9 | public class StringValuedEnumReflect { 10 | 11 | /** 12 | * Don't let anyone instantiate this class. 13 | * @throws UnsupportedOperationException Always. 14 | */ 15 | private StringValuedEnumReflect() { 16 | throw new UnsupportedOperationException("This class must not be instantiated."); 17 | } 18 | 19 | /** 20 | * All Enum constants (instances) declared in the specified class. 21 | * @param enumClass Class to reflect 22 | * @param Type 23 | * @return Array of all declared EnumConstants (instances). 24 | */ 25 | @SuppressWarnings("rawtypes") 26 | private static T[] 27 | getValues(Class enumClass) { 28 | return enumClass.getEnumConstants(); 29 | } 30 | 31 | /** 32 | * All possible string values of the string valued enum. 33 | * @param enumClass Class to reflect. 34 | * @param Type 35 | * @return Available string values. 36 | */ 37 | @SuppressWarnings("rawtypes") 38 | public static String[] 39 | getStringValues(Class enumClass) { 40 | T[] values = getValues(enumClass); 41 | String[] result = new String[values.length]; 42 | for (int i = 0; i < values.length; i++) { 43 | result[i] = values[i].getValue(); 44 | } 45 | return result; 46 | } 47 | 48 | /** 49 | * Name of the enum instance which hold the especified string value. 50 | * If value has duplicate enum instances than returns the first occurency. 51 | * @param enumClass Class to inspect. 52 | * @param value String. 53 | * @param Type 54 | * @return name of the enum instance. 55 | */ 56 | @SuppressWarnings("rawtypes") 57 | public static String 58 | getNameFromValue(Class enumClass, Object value) { 59 | T[] values = getValues(enumClass); 60 | for (int i = 0; i < values.length; i++) { 61 | if (reflectGetValue(values[i]).equals(value.toString().trim())) { 62 | return values[i].name(); 63 | } 64 | } 65 | return ""; 66 | } 67 | 68 | public static String reflectGetValue(Object v){ 69 | try { 70 | return (String)v.getClass().getMethod("getValue").invoke(v); 71 | } catch ( InvocationTargetException | IllegalAccessException | NoSuchMethodException e4) { 72 | return "Unable to return a value from String Valued Enum"; 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/classIface.vm: -------------------------------------------------------------------------------- 1 | package ${packagename}; 2 | ### 3 | ######## Macros 4 | #macro(prefix) 5 | #if ( $property.isBooleanField() && !$property.isIdField())is#{else}get#end 6 | #end 7 | ## 8 | #################################### END MACROS #################### 9 | #foreach( $import in $imports ) 10 | import $import; 11 | #end 12 | #set ($fullTypeOfId = "---") 13 | 14 | 15 | /** 16 | * Object interface mapping for hibernate-handled table: ${class.tableObj.dbName}. 17 | * @author autogenerated 18 | */ 19 | 20 | public interface I$class.className#if($class.subclass) extends I$class.extendsFrom.clazz.className#end { 21 | 22 | 23 | ## 24 | ## 25 | ## Getters 26 | ## 27 | ## 28 | #foreach( $property in $properties ) 29 | #set ($fullTypeOfId = "$property.JavaType") 30 | #if ( $property.oneToMany) 31 | #set ($fullType = "Set<$property.JavaType>") 32 | #set ($fullJDType = "Set<$property.JavaType>") 33 | #else 34 | #if ( $property.manyToMany ) 35 | #set ($fullType = "Set<$property.manyToManyLink.dstProperty.clazz.className>") 36 | #set ($fullJDType = "Set<$property.manyToManyLink.dstProperty.clazz.className>") 37 | #else 38 | #set ($fullType = "$property.JavaType") 39 | #set ($fullJDType = "$property.JavaType") 40 | #end 41 | #end 42 | 43 | /** 44 | * Return the value associated with the column: $property.propertyName. 45 | * @return A $fullJDType object (this.$property.propertyName) 46 | */ 47 | $fullType #prefix()${property.niceJavaName}(); 48 | 49 | ## 50 | ## 51 | ## one-to-many 52 | ## 53 | ## 54 | #if ( $property.oneToMany ) 55 | /** 56 | * Adds a bi-directional link of type ${property.JavaName} to the ${property.nicePropertyName} set. 57 | * @param $property.propertyName item to add 58 | */ 59 | void add${property.JavaName}(${property.javaType} $property.propertyName); 60 | #end 61 | ## 62 | ## 63 | ## 64 | ## many-to-many 65 | ## 66 | ## 67 | #if ( $property.ManyToMany ) 68 | /** 69 | * Adds a bi-directional link of type ${property.JavaName} to the set. 70 | * @param $property.propertyName item to add 71 | */ 72 | void add${property.JavaName}(${property.javaType} $property.propertyName); 73 | #end 74 | 75 | ## 76 | ## 77 | ## Setters 78 | ## 79 | ## 80 | 81 | /** 82 | * Set the value related to the column: $property.propertyName. 83 | * @param $property.propertyName the $property.propertyName value you wish to set 84 | */ 85 | void set${property.niceJavaName}(final $fullType $property.propertyName); 86 | #end 87 | 88 | ## Join Tables 89 | #foreach ($joinMap in $class.joinMappings) 90 | #if ($joinmap.dstProperty.clazz.isInNoOutputList) 91 | 92 | /** 93 | * Utility method to add a ${joinMap.dstProperty.clazz.className} by using the link class table ($joinMap.linkClass.className). 94 | * This method takes care of maintaining the proper bidirectional links 95 | * @param ${joinMap.dstProperty.clazz.getClassPropertyName()} ${joinMap.dstProperty.clazz.className} object to add 96 | * @return $joinMap.linkClass.className The linker object. 97 | */ 98 | $joinMap.linkClass.className add${joinMap.dstProperty.clazz.className}(${joinMap.dstProperty.clazz.className} ${joinMap.dstProperty.clazz.getClassPropertyName()}); 99 | #end 100 | #end 101 | // end of interface 102 | } -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/classRepo.vm: -------------------------------------------------------------------------------- 1 | package ${packagename}; 2 | 3 | import ${springRepo}; 4 | import org.springframework.data.querydsl.QuerydslPredicateExecutor; 5 | import ${impl}; 6 | import java.io.Serializable; 7 | 8 | /** 9 | * Spring Data Repository for table: ${class.tableObj.dbName}. 10 | * @author autogenerated/custom 11 | */ 12 | public interface ${class.className}Repository extends ${springRepoShort}<${class.className}, ${id}>, QuerydslPredicateExecutor<${class.className}> { 13 | 14 | // Add any extra methods here. This file will not get overwritten unlike any other generated file 15 | } 16 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/dao.vm: -------------------------------------------------------------------------------- 1 | package ${packagename}; 2 | 3 | import GenericHibernateDaoImpl; 4 | import ${objpackagename}; 5 | import org.springframework.stereotype.Repository; 6 | import ${daoImport}.${class.className}Dao; 7 | $importPK 8 | 9 | /** 10 | * DAO for table: $class.className. 11 | * @author autogenerated 12 | */ 13 | @Repository#if($class.isNameAmbiguityPossible())(value = "$class.getDAOBean()")#end 14 | 15 | public class ${class.className}DaoImpl extends GenericHibernateDaoImpl<$class.className, ${class.getTypeOfId()}> implements ${class.className}Dao { 16 | 17 | /** Constructor method. */ 18 | public ${class.className}DaoImpl() { 19 | super(${class.className}.class); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/daoFactory.vm: -------------------------------------------------------------------------------- 1 | package ${packagename}; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.beans.factory.BeanNameAware; 9 | 10 | #foreach ($import in $imports) 11 | import $import; 12 | #end 13 | 14 | /** 15 | * DAO factory implementation. 16 | * @author autogenerated 17 | */ 18 | @Component 19 | public class Hibernate${prettyCatalog}DaoFactory implements ApplicationContextAware, BeanNameAware { 20 | /** Placeholder for an instance. */ 21 | private static Hibernate${prettyCatalog}DaoFactory instance; 22 | /** Internal state. */ 23 | private static ApplicationContext context = null; 24 | /** Bean Name. */ 25 | private static String beanName; 26 | 27 | /** Return an instance of this class. 28 | * @return an instance of this class 29 | */ 30 | public static synchronized Hibernate${prettyCatalog}DaoFactory getInstance() { 31 | if (instance == null) { 32 | instance = (Hibernate${prettyCatalog}DaoFactory) context.getBean(beanName); 33 | } 34 | return instance; 35 | } 36 | 37 | /** 38 | * Sets a Spring Application Context object. 39 | * @param ctxt ApplicationContext to set 40 | * @throws BeansException on spring error 41 | */ 42 | @Autowired 43 | public void setApplicationContext(ApplicationContext ctxt) 44 | throws BeansException 45 | { 46 | context = ctxt; 47 | } 48 | 49 | /** 50 | * 51 | * {@inheritDoc} 52 | * 53 | * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String) 54 | */ 55 | public void setBeanName(String name) { 56 | beanName = name; 57 | } 58 | 59 | /** 60 | * Return the requested bean from the context, throwing a RuntimeException on error. 61 | * 62 | * @param beanName to return 63 | * @return the bean requested. 64 | */ 65 | public static Object getBean(String beanName) { 66 | Object result = context.getBean(beanName); 67 | if (result == null) { 68 | throw new IllegalStateException(String.format("Could not find bean '%s'. Did you set the right component scanning?", beanName)); 69 | } 70 | 71 | return result; 72 | } 73 | 74 | 75 | #foreach ($class in $classes) 76 | #if (! $class.isEmbeddable() && (! $class.isHiddenJoinTable()) ) 77 | /** 78 | * Returns a ${class.className}Dao instance. 79 | * 80 | * @return a ${class.className}Dao instance 81 | */ 82 | public static ${class.className}Dao get${class.className}Dao() { 83 | return (${class.className}Dao) getBean("${class.getDAOBean()}"); 84 | } 85 | #end 86 | #end 87 | 88 | } 89 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/daoInterface.vm: -------------------------------------------------------------------------------- 1 | package ${packagename}; 2 | 3 | import GenericDAO; 4 | import ${objpackagename}; 5 | $importPK 6 | /** 7 | * DAO interface for table: $class.className. 8 | * @author autogenerated 9 | */ 10 | public interface ${class.className}Dao extends GenericDAO<$class.className, ${class.getTypeOfId()}> { 11 | // constructor only 12 | } 13 | 14 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/dataPoolFactoryInterface.vm: -------------------------------------------------------------------------------- 1 | package ${packagename}; 2 | 3 | import java.util.Collection; 4 | /** 5 | * DAO factory interface 6 | * @author autogenerated 7 | */ 8 | public interface DataPoolFactory { 9 | 10 | /** Returns the commit order of this database. 11 | * Useful for iterating through the classes for deletion in the right order. 12 | * @return String[] list of classes 13 | */ 14 | String[] getDBCommitOrder(); 15 | 16 | /** As getDBCommitOrder but returns type safe classes instead. */ 17 | Class[] getDBClassCommitOrder(); 18 | 19 | /** 20 | * @param className classname to return 21 | * @return the tabledeps for the given class name 22 | */ 23 | Collection getTabledeps(String className); 24 | 25 | /** 26 | * Returns the schema that we used to generate this factory. 27 | * @return Schema name 28 | */ 29 | String getSchema(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/ehcache.vm: -------------------------------------------------------------------------------- 1 | 5 | 6 | 19 | 20 | 21 | 25 | 34 | 35 | 36 | 37 | 44 | 45 | 49 | 50 | 51 | #foreach ($classname in $classes) 52 | 60 | #end 61 | 62 | 63 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/enum.vm: -------------------------------------------------------------------------------- 1 | package ${packagename}; 2 | import java.util.Map; 3 | import java.util.HashMap; 4 | /** 5 | * Defines the ${enumName} enumeration. 6 | * 7 | * @author autogenerated 8 | * 9 | */ 10 | public enum ${enumName} { 11 | 12 | #set ($count = 0) 13 | #foreach ( $enum in $enums ) 14 | #set ( $count = $count+1 ) 15 | /** Enum Constant. */ 16 | $enum#if ($count == $enumCount);#else,#end 17 | 18 | #end 19 | #macro(state) 20 | #foreach ($other in ${others.entrySet()}), $other.getValue().getClass().getSimpleName() $other.getKey()#end 21 | #end 22 | /** 23 | * Internal storage of status field value, see the Enum spec for 24 | * clarification. 25 | */ 26 | private final String status; 27 | #foreach ($other in $others.entrySet()) 28 | /** Internal state. */ 29 | private final $other.getValue().getClass().getSimpleName() $other.getKey(); 30 | #end 31 | 32 | /** 33 | * Enum constructor for ActiveState. 34 | * @param state Value. 35 | #foreach ($other in $others.keySet()) 36 | * @param $other enum value 37 | #end 38 | */ 39 | ${enumName}(final String state#state()) { 40 | this.status = state; 41 | #foreach ($other in $others.keySet()) 42 | this.$other = $other; 43 | #end 44 | } 45 | 46 | /** Construct a map for reverse lookup. */ 47 | private static Map valueMap = new HashMap(); 48 | #foreach ($other in $others.entrySet()) 49 | /** Construct a map for reverse lookup of $other.getKey(). */ 50 | private static Map<$other.getValue().getClass().getSimpleName(), ${enumName}> ${other.getKey()}Map = new HashMap<>(); 51 | #end 52 | 53 | static { 54 | // construct hashmap for later possible use. 55 | for (${enumName} unit : values()) { 56 | valueMap.put(unit.getValue(), unit); 57 | #foreach ($other in $others.entrySet()) 58 | ${other.getKey()}Map.put(unit.get${this.upFirst($other.getKey())}(), unit); 59 | #end 60 | } 61 | } 62 | 63 | /** 64 | * Current string value stored in the enum. 65 | * 66 | * @return string value. 67 | */ 68 | public String getValue() { 69 | return this.status; 70 | } 71 | 72 | #foreach ($other in $others.entrySet()) 73 | /** 74 | * Current $other.getKey() value stored in the enum. 75 | * 76 | * @return $other.getValue().getClass().getSimpleName() value representing $other.getKey(). 77 | */ 78 | public $other.getValue().getClass().getSimpleName() get${this.upFirst($other.getKey())}() { 79 | return this.${other.getKey()}; 80 | } 81 | #end 82 | /** 83 | * Perform a reverse lookup (given a value, obtain the enum). 84 | * 85 | * @param value to search 86 | * @return Enum object. 87 | */ 88 | public static ${enumName} lookupEnum(String value) { 89 | return ${enumName}.valueMap.get(value); 90 | } 91 | #foreach ($other in $others.entrySet()) 92 | /** 93 | * Perform a reverse lookup (given $other.getKey(), obtain the enum). 94 | * 95 | * @param $other.getKey() to search 96 | * @return Enum object. 97 | */ 98 | public static ${enumName} lookupEnumBy$other.getKey()($other.getValue().getClass().getSimpleName() $other.getKey()) { 99 | return ${enumName}.${other.getKey()}Map.get($other.getKey()); 100 | } 101 | #end 102 | 103 | } 104 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/enumClass.vm: -------------------------------------------------------------------------------- 1 | package ${packagename}; 2 | /** 3 | * Defines the ${enumName} enumeration. 4 | * 5 | * @author autogenerated 6 | * 7 | */ 8 | public enum ${enumName} { 9 | 10 | #set ($count = 0) 11 | #foreach ( $enum in $enums ) 12 | #set ( $count = $count+1 ) 13 | /** Enum Constant. */ 14 | $enum#if ($count == $enumCount);#else,#end 15 | 16 | #end 17 | 18 | } 19 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/hbnPojoGenBuild.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/mocktest.vm: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | #foreach( $class in $classes ) 9 | 10 | 11 | 12 | 13 | #end 14 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/openapi-allpaths.vm: -------------------------------------------------------------------------------- 1 | # This is just a convenience snippet to help you cut and paste the urls you care about 2 | paths: 3 | #foreach ( $class in $classes ) 4 | #if (!$class.isHiddenJoinTable()) 5 | /$class.toKebabCase(): 6 | $ref: "./openapi-schemas/${class.className}.yaml#/paths/getall_post" 7 | /$class.toKebabCase()/{id}: 8 | $ref: "./openapi-schemas/${class.className}.yaml#/paths/getone_put" 9 | #end 10 | #end 11 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/openapi-delegate.vm: -------------------------------------------------------------------------------- 1 | package ${toplevel}.controller.delegate; 2 | 3 | import ${toplevel}.${class.className}ApiController; 4 | import ${toplevel}.db.model.generated.${class.className}; 5 | import ${toplevel}.db.model.repository.${class.className}Repository; 6 | import ${toplevel}.model.${class.className}Dto; 7 | import ${openapiCommonPackage}.controller.AbstractCommonCrudService; 8 | import ${openapiCommonPackage}.controller.CommonCrudService; 9 | import ${openapiCommonPackage}.entity.EntityId; 10 | import com.querydsl.core.types.Predicate; 11 | import lombok.extern.slf4j.Slf4j; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.data.domain.Page; 14 | import org.springframework.data.domain.Pageable; 15 | import org.springframework.data.domain.Sort; 16 | import org.springframework.http.HttpHeaders; 17 | import org.springframework.http.ResponseEntity; 18 | import org.springframework.stereotype.Component; 19 | 20 | import java.security.Principal; 21 | 22 | @Component @Slf4j 23 | public class ${class.className}ApiDelegateImpl extends AbstractCommonCrudService implements ${toplevel}.${class.className}ApiDelegate, CommonCrudService<${class.className}, ${class.className}ApiController> { 24 | 25 | @Override 26 | public void update${class.className}(${class.className}Dto ${class.className.toLowerCase()}Dto, HttpHeaders headers, Principal principal) { 27 | update(${class.className.toLowerCase()}Dto.getId(), ${class.className.toLowerCase()}Dto, principal); 28 | } 29 | 30 | 31 | @Override 32 | public ${class.className}Dto get${class.className}ById(EntityId ${class.getClassPropertyName()}Id, HttpHeaders headers, Principal principal) { 33 | return getById(${class.getClassPropertyName()}Id, principal, ${class.className}Dto.class); 34 | } 35 | 36 | 37 | @Override 38 | public Page<${class.className}Dto> get${class.niceClassName}(Predicate predicate, Pageable pageable, Sort sortable, HttpHeaders headers, Principal principal) { 39 | return load(predicate, pageable, sortable, ${class.className}Dto.class, principal); 40 | } 41 | 42 | @Override 43 | public ResponseEntity<${class.className}Dto> create${class.className}(${class.className}Dto ${class.getClassPropertyName()}Dto, HttpHeaders headers, Principal principal) { 44 | return (ResponseEntity<${class.className}Dto>) add(${class.getClassPropertyName()}Dto, principal); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/openapi-reference-docs.vm: -------------------------------------------------------------------------------- 1 | = Generated Docs 2 | Generated Docs; 3 | :doctype: book 4 | :icons: font 5 | :source-highlighter: highlightjs 6 | :toc: left 7 | :toclevels: 4 8 | :sectlinks: 9 | :operation-curl-request-title: Example request 10 | :operation-http-response-title: Example response 11 | 12 | 13 | [[overview]] 14 | == Introduction 15 | 16 | 17 | Welcome to Docs! 18 | 19 | 20 | This guide will assist you in integrating with our services as quickly as possible; if you already know the basics 21 | you may wish to refer to our http://docs.domain.com/index.html[Quick reference API guide] instead. 22 | 23 | === Overview 24 | 25 | 26 | Wherever possible, we recommend you use the higher-level APIs we provide for your target platform such as Android or iOS but 27 | at the heart of all interactions with our API lies a simple RESTful API that supports the creation, retrieval, 28 | and deletion of various resources as described below. The API authorizes access using http://tools.ietf.org/html/rfc6749[OAuth 2.0] and will 29 | therefore expect most calls to be authenticated to succeed. All calls are made to either a live environment at http://api.domain.com 30 | or a testing environment at http://apisandbox.domain.com that you may use for integration testing purposes. 31 | 32 | You make calls using standard HTTP conventions in http://www.json.org[JSON] format and expect the same format back for all 33 | API responses whether successful or not. Errors are communicated via standard HTTP error codes as per REST convention as well as via error fields in responses. 34 | 35 | 36 | 37 | [[overview-http-verbs]] 38 | ==== HTTP verbs 39 | 40 | The API tries to adhere as closely as possible to standard HTTP and REST conventions in its 41 | use of HTTP verbs. For example: 42 | 43 | |=== 44 | | Verb | Usage 45 | 46 | | `GET` 47 | | Used to retrieve a resource 48 | 49 | | `POST` 50 | | Used to create a new resource 51 | 52 | | `DELETE` 53 | | Used to delete an existing resource 54 | |=== 55 | 56 | [[overview-http-status-codes]] 57 | ==== HTTP status codes 58 | 59 | Following the same REST conventions, the API makes use of the following error codes. 60 | 61 | |=== 62 | | Status code | Usage 63 | 64 | | `200 OK` 65 | | The request completed successfully 66 | 67 | | `201 Created` 68 | | A new resource has been created successfully. The resource's URI is available from the response's 69 | `Location` header 70 | 71 | | `204 No Content` 72 | | An update to an existing resource has been applied successfully 73 | 74 | | `400 Bad Request` 75 | | The request was malformed. The response body will include an error providing further information 76 | 77 | | `401 Unauthorized` 78 | | The request was not authorized for the given bearer token or username/password. 79 | 80 | | `404 Not Found` 81 | | The requested resource did not exist 82 | |=== 83 | ---- 84 | ---- 85 | 86 | 87 | 88 | [[auth]] 89 | == Authentication 90 | 91 | 92 | [NOTE] 93 | ==== 94 | Remember to contact our support department to provide you with the appropriate credentials. 95 | ==== 96 | 97 | Authentication to the platform is based around http://tools.ietf.org/html/rfc6749[OAuth 2.0]. We strongly recommend using 98 | existing client-side libraries to deal with all your authentication details. 99 | 100 | Before you make any other call, you must first authenticate in order to obtain a token -- this token is then used in all 101 | subsequent calls to the platform. 102 | 103 | 104 | The REST URL to invoke via a POST request is ``https://api.domain.com/auth`` and requires you to post the client credentials as assigned to you by your 105 | account manager. These assigned ``clientId`` and ``clientSecret`` are passed along the 106 | ``Authorization: Bearer`` header. 107 | 108 | 109 | [source,bash,role="primary"] 110 | 111 | ---- 112 | $ curl -X POST \ 113 | https://api.domain.com/auth \ 114 | -H 'content-type: application/json' \ 115 | -d '{"grant_type":"password","username": "yourAssignedUsername","password":"yourAssignedPassword", "client_id": "123456"}' 116 | 117 | ---- 118 | 119 | The response would be in this http://tools.ietf.org/html/rfc6749#section-4.4.3[standard JSON document format] from the OAuth 2.0 specification. 120 | [source,bash,role="primary"] 121 | ---- 122 | { 123 | { 124 | "access_token": "eyJ0eX...", 125 | "expires_in": 86400, 126 | "token_type": "Bearer" 127 | } 128 | } 129 | ---- 130 | 131 | 132 | === Invoking the API 133 | 134 | For any subsequent API call, include the access token returned in the authorization call as in the following example: 135 | 136 | [source,bash,role="primary"] 137 | 138 | ---- 139 | 140 | $ curl --header "Authorization: Bearer eyJ0eX" 'https://...' 141 | ---- 142 | 143 | [[resources]] 144 | 145 | 146 | #foreach ( $class in $classes ) 147 | #if (!$class.isHiddenJoinTable()) 148 | 149 | === Create ${class.className} 150 | 151 | operation::add${class.className}[snippets='curl-request,http-request,http-response,request-fields'] 152 | 153 | 154 | === Get multiple ${class.niceClassName} 155 | 156 | operation::get${class.niceClassName}[snippets='curl-request,http-request,http-response,response-fields'] 157 | 158 | === Get single ${class.className} 159 | 160 | You may fetch a single ${class.className} via the following API call. 161 | 162 | operation::getSingle${class.className}[snippets='curl-request,http-request,http-response,response-fields'] 163 | 164 | #end 165 | #end -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/openapi-schema.vm: -------------------------------------------------------------------------------- 1 | $class.className: 2 | type: object 3 | properties: 4 | #foreach( $property in $properties ) 5 | #if ( !$property.oneToMany && !$property.manyToMany ) 6 | $property.propertyName: 7 | #if ( $property.isRefField() ) 8 | allOf: 9 | - $property.computedOpenApiType 10 | #else 11 | $property.computedOpenApiType 12 | #end 13 | #if ( $property.openApiFormat) 14 | format: $property.openApiFormat 15 | #end 16 | #if ( !$property.isNullable() ) 17 | nullable: false 18 | #end 19 | #if ( $property.isOpenApiReadOnlyField() ) 20 | readOnly: true 21 | #end 22 | #if ( $property.openApiWriteOnlyField ) 23 | writeOnly: true 24 | #end 25 | #if ( $property.openApiEnumValues) 26 | enum: $property.openApiEnumValues 27 | #end 28 | #if ( $property.length) 29 | maxLength: $property.length 30 | #end 31 | #if ( !$property.getFieldComment().equals("")) 32 | description: $property.getFieldComment() 33 | #end 34 | #end 35 | #end 36 | 37 | paths: 38 | getOne: 39 | get: &getoneanchor 40 | tags: 41 | - $class.className 42 | summary: Get $class.className.toLowerCase() by Id 43 | description: "Get a single record associated with the given ID" 44 | operationId: get${class.className}ById 45 | parameters: 46 | - name: $class.className.toLowerCase()Id 47 | in: path 48 | description: ID of $class.className.toLowerCase() 49 | required: true 50 | x-encrypted-id: true 51 | schema: 52 | type: string 53 | responses: 54 | "200": 55 | description: Request accepted 56 | content: 57 | application/json: 58 | schema: 59 | $ref: "#/$class.className" 60 | "400": 61 | $ref: "${this.openApiCommon()}#/responses/Standard400Response" 62 | "401": 63 | $ref: "${this.openApiCommon()}#/responses/Standard401Response" 64 | "403": 65 | $ref: "${this.openApiCommon()}#/responses/Standard403Response" 66 | "404": 67 | $ref: "${this.openApiCommon()}#/responses/Standard404Response" 68 | create: 69 | post: &postanchor 70 | tags: 71 | - $class.className 72 | summary: Create a new $class.className.toLowerCase() 73 | description: "" 74 | operationId: create$class.className 75 | requestBody: 76 | content: 77 | application/json: 78 | schema: 79 | $ref: "#/$class.className" 80 | required: true 81 | responses: 82 | "201": 83 | description: The request has been fulfilled and has resulted in one or more new resources being created. 84 | content: 85 | application/json: 86 | schema: 87 | $ref: "#/$class.className" 88 | "400": 89 | $ref: "${this.openApiCommon()}#/responses/Standard400Response" 90 | "401": 91 | $ref: "${this.openApiCommon()}#/responses/Standard401Response" 92 | "403": 93 | $ref: "${this.openApiCommon()}#/responses/Standard403Response" 94 | "409": 95 | $ref: "${this.openApiCommon()}#/responses/Standard409Response" 96 | update: 97 | put: &updateanchor 98 | tags: 99 | - $class.className 100 | summary: Update a $class.className.toLowerCase() 101 | description: "" 102 | operationId: update$class.className 103 | requestBody: 104 | content: 105 | application/json: 106 | schema: 107 | $ref: "#/$class.className" 108 | required: true 109 | responses: 110 | "201": 111 | $ref: "${this.openApiCommon()}#/responses/Standard200Response" 112 | "400": 113 | $ref: "${this.openApiCommon()}#/responses/Standard400Response" 114 | "401": 115 | $ref: "${this.openApiCommon()}#/responses/Standard401Response" 116 | "403": 117 | $ref: "${this.openApiCommon()}#/responses/Standard403Response" 118 | "409": 119 | $ref: "${this.openApiCommon()}#/responses/Standard409Response" 120 | delete: 121 | get: &deleteanchor 122 | tags: 123 | - $class.className 124 | summary: Deletes $class.className.toLowerCase() by Id 125 | description: "Deletes a single record associated with the given ID" 126 | operationId: delete${class.className}ById 127 | parameters: 128 | - name: $class.className.toLowerCase()Id 129 | in: path 130 | description: ID of $class.className.toLowerCase() 131 | required: true 132 | x-encrypted-id: true 133 | schema: 134 | type: string 135 | responses: 136 | "200": 137 | description: Request accepted 138 | content: 139 | application/json: 140 | schema: 141 | $ref: "#/$class.className" 142 | "400": 143 | $ref: "${this.openApiCommon()}#/responses/Standard400Response" 144 | "401": 145 | $ref: "${this.openApiCommon()}#/responses/Standard401Response" 146 | "403": 147 | $ref: "${this.openApiCommon()}#/responses/Standard403Response" 148 | "404": 149 | $ref: "${this.openApiCommon()}#/responses/Standard404Response" 150 | getAll: 151 | get: &getallanchor 152 | tags: 153 | - $class.className 154 | summary: Get list of $class.getNiceClassName().toLowerCase() 155 | operationId: get$class.getNiceClassName() 156 | parameters: 157 | - $ref: "${this.openApiCommon()}#/components/parameters/pageParam" 158 | - $ref: "${this.openApiCommon()}#/components/parameters/sizeParam" 159 | - in: query 160 | name: sort 161 | x-ignore-param: true 162 | schema: 163 | type: string 164 | responses: 165 | "200": 166 | description: Request accepted 167 | content: 168 | application/json: 169 | schema: 170 | type: array 171 | items: 172 | $ref: "#/$class.className" 173 | "400": 174 | $ref: "${this.openApiCommon()}#/responses/Standard400Response" 175 | "401": 176 | $ref: "${this.openApiCommon()}#/responses/Standard401Response" 177 | "403": 178 | $ref: "${this.openApiCommon()}#/responses/Standard403Response" 179 | "404": 180 | $ref: "${this.openApiCommon()}#/responses/Standard404Response" 181 | x-querydsl-binding: QueryDslBinder 182 | x-payload-class: Page 183 | 184 | 185 | getone_put: 186 | get: *getoneanchor 187 | put: *updateanchor 188 | getone_delete: 189 | get: *getoneanchor 190 | delete: *deleteanchor 191 | getall_post: 192 | get: *getallanchor 193 | post: *postanchor 194 | post_delete: 195 | post: *postanchor 196 | delete: *deleteanchor 197 | put_delete: 198 | put: *updateanchor 199 | delete: *deleteanchor 200 | getone_put_delete: 201 | get: *getoneanchor 202 | put: *updateanchor 203 | delete: *deleteanchor 204 | 205 | -------------------------------------------------------------------------------- /hbnpojogen-core/src/main/resources/templates/openapi-test.vm: -------------------------------------------------------------------------------- 1 | // Autogenerated class, probably requires tweaking 2 | package ${packageToUse}; 3 | 4 | import ${toplevel}.AbstractGenericTest; 5 | 6 | import ${toplevel}.db.model.repository.*; 7 | import ${toplevel}.model.*; 8 | 9 | import ${toplevel}.db.model.generated.*; 10 | import ${toplevel}.db.model.generated.factories.*; 11 | import ${openapiCommonPackage}.beans.CommonBeansAutoConfiguration; 12 | import org.junit.Test; 13 | import org.junit.runner.RunWith; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.boot.test.context.SpringBootTest; 16 | import org.springframework.context.annotation.ComponentScan; 17 | import org.springframework.context.annotation.Import; 18 | import org.springframework.security.test.context.support.WithMockUser; 19 | import org.springframework.test.context.junit4.SpringRunner; 20 | import static org.springframework.restdocs.payload.PayloadDocumentation.*; 21 | 22 | 23 | 24 | @SpringBootTest 25 | @RunWith(SpringRunner.class) 26 | @ComponentScan(basePackageClasses = ${toplevel}.Application.class) 27 | @Import(CommonBeansAutoConfiguration.class) 28 | @WithMockUser("xyz") 29 | public class GeneratedDocsTest extends AbstractGenericTest{ 30 | 31 | 32 | #foreach ( $class in $classes ) 33 | #if (!$class.isHiddenJoinTable()) 34 | @Autowired 35 | ${class.className}Repository ${class.getClassPropertyName()}Repository; 36 | 37 | #end 38 | #end 39 | #foreach ( $class in $classes ) 40 | #if (!$class.isHiddenJoinTable()) 41 | 42 | 43 | @Test 44 | public void shouldGet${class.getNiceClassName()}() throws Exception { 45 | 46 | ${class.getMaybeExpandClassName()} ${class.tableObj.testHandle} = ${class.getDataPoolFactoryImpl()}.get${class.className}(); 47 | ${class.getClassPropertyName()}Repository.save(${class.tableObj.testHandle}); 48 | 49 | 50 | retrieve("/${class.toKebabCase()}", ${class.tableObj.testHandle}.getId(), ${class.className}Dto.class, "get${class.getNiceClassName()}", 51 | responseFields( 52 | #foreach( $property in $class.getOpenApiTestProperties() ) 53 | fieldWithPath("content[].${property.propertyName}").description("${property.fieldObj.comment}")#if ($property.fieldObj.nullable).optional()#end#if ($velocityCount < $class.getOpenApiTestProperties().size()),#end 54 | 55 | #end 56 | ).and(standardListFieldDescriptors) 57 | ); 58 | } 59 | 60 | 61 | @Test 62 | public void shouldRetrieveSingle${class.className}() throws Exception{ 63 | ${class.getMaybeExpandClassName()} ${class.tableObj.testHandle} = ${class.getDataPoolFactoryImpl()}.get${class.className}(); 64 | ${class.tableObj.testHandle} = ${class.getClassPropertyName()}Repository.save(${class.tableObj.testHandle}); 65 | String id = entityIdUtils.encrypt(${class.tableObj.testHandle}.getId()); 66 | 67 | 68 | executeGetCall("/${class.toKebabCase()}/{id}", new String[]{id}, "getSingle${class.className}", 69 | responseFields( 70 | #foreach( $property in $class.getOpenApiTestProperties() ) 71 | fieldWithPath("${property.propertyName}").description("${property.fieldObj.comment}")#if ($property.fieldObj.nullable).optional()#end#if ($velocityCount < $class.getOpenApiTestProperties().size()),#end 72 | 73 | #end 74 | ), 75 | null 76 | ); 77 | } 78 | 79 | @Test 80 | public void shouldCreateNew${class.className}() throws Exception { 81 | 82 | ${class.getMaybeExpandClassName()} ${class.tableObj.testHandle} = ${class.getDataPoolFactoryImpl()}.get${class.className}(); 83 | ${class.getClassPropertyName()}Repository.save(${class.tableObj.testHandle}); 84 | 85 | 86 | 87 | ConstrainedFields fields = new ConstrainedFields(${class.className}Dto.class); 88 | 89 | // hard-coded so that we break if we ever change API 90 | String request = "${class.generateJsonExample()}"; 91 | 92 | createNew("/${class.toKebabCase()}/", request, ${class.getClassPropertyName()}Repository, "add${class.className}", requestFields( 93 | #foreach( $property in $class.getOpenApiTestProperties() ) 94 | fields.withPath("${property.nicePropertyName}").description("${property.fieldObj.comment}")#if ($velocityCount < $class.getOpenApiTestProperties().size()),#end 95 | 96 | #end 97 | ) 98 | ); 99 | } 100 | 101 | #end 102 | #end 103 | } -------------------------------------------------------------------------------- /hbnpojogen-maven/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /hbnpojogen-maven/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | hbnpojogen-maven 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /hbnpojogen-maven/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Tue Aug 17 12:38:59 CEST 2010 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.compliance=1.6 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.source=1.6 7 | -------------------------------------------------------------------------------- /hbnpojogen-maven/.settings/org.maven.ide.eclipse.prefs: -------------------------------------------------------------------------------- 1 | #Tue Aug 17 12:38:59 CEST 2010 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | fullBuildGoals=process-test-resources 5 | includeModules=false 6 | resolveWorkspaceProjects=true 7 | resourceFilterGoals=process-resources resources\:testResources 8 | skipCompilerPlugin=true 9 | version=1 10 | -------------------------------------------------------------------------------- /hbnpojogen-maven/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 4.0.0 5 | 6 | 7 | hbnpojogen 8 | com.github.wwadge 9 | 1.5.13 10 | 11 | 12 | hbnpojogen-maven-plugin 13 | maven-plugin 14 | 15 | Hibernate Synchronizer Maven Plugin 16 | Hibernate Synchronizer Maven Plugin 17 | 18 | 19 | 2.2.1 20 | 21 | 22 | 23 | 24 | com.github.wwadge 25 | hbnpojogen-core 26 | 27 | 28 | 29 | org.apache.maven 30 | maven-plugin-api 31 | ${maven.version} 32 | 33 | 34 | 35 | org.apache.maven 36 | maven-project 37 | ${maven.version} 38 | 39 | 40 | 41 | org.apache.maven 42 | maven-model 43 | ${maven.version} 44 | 45 | 46 | -------------------------------------------------------------------------------- /hbnpojogen-maven/src/main/java/com/github/wwadge/hbnpojogen/SynchronizerMojo.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen; 2 | 3 | 4 | import org.apache.maven.plugin.AbstractMojo; 5 | import org.apache.maven.plugin.MojoExecutionException; 6 | import org.apache.maven.plugin.MojoFailureException; 7 | import org.apache.maven.project.MavenProject; 8 | 9 | import java.io.File; 10 | 11 | 12 | /** 13 | * The Hibernate Sychronizer mojo. 14 | * 15 | * @author wallacew 16 | * @goal generate 17 | * @phase generate-sources 18 | * @description Creates all the hibernate/spring stuff required to access a DB 19 | */ 20 | public class SynchronizerMojo extends AbstractMojo { 21 | 22 | /** 23 | * The name of the XML config file to use. If you omit this, attempt to load hbnpojogen.config.xml 24 | * from the classpath. 25 | * 26 | * @parameter property="configFile" 27 | * @optional 28 | */ 29 | protected String configFile; 30 | 31 | /** 32 | * The artifactId of the child that will contain the generated sources. 33 | * 34 | * @parameter property="modelArtifactId" 35 | * @required 36 | */ 37 | protected String modelArtifactId; 38 | 39 | /** 40 | * The project object model. 41 | * 42 | * @parameter property="project" 43 | * @readonly 44 | * @required 45 | */ 46 | protected MavenProject mavenProject; 47 | 48 | /** 49 | * ipaddress to use as source (override). 50 | * 51 | * @parameter property="ip" 52 | * @optional 53 | */ 54 | protected String ip; 55 | 56 | /** 57 | * temp. 58 | */ 59 | protected String target; 60 | 61 | /** 62 | * If this is declared, the model generation will start. 63 | * 64 | * @parameter property="generateModel" 65 | * @optional 66 | */ 67 | protected Boolean generateModel; 68 | 69 | // @SuppressWarnings("unchecked") 70 | public void execute() throws MojoExecutionException, MojoFailureException { 71 | if (this.generateModel == null || !this.generateModel) { 72 | getLog().info("Skipping model generation. Run with -DgenerateModel to enable."); 73 | } else { 74 | 75 | File f = new File(this.mavenProject.getBasedir(), this.configFile == null ? "hbnpojogen.config.xml" : this.configFile); 76 | if (f.exists()) { 77 | this.configFile = f.getAbsolutePath(); 78 | } else { 79 | throw new MojoFailureException("Could not find " + f.getAbsolutePath()); 80 | } 81 | 82 | this.target = this.mavenProject.getBasedir().getAbsolutePath() + File.separator + this.modelArtifactId; 83 | HbnPojoGen.setLog(getLog()); 84 | HbnPojoGen.run(this.configFile, this.target, this.ip); 85 | 86 | } 87 | } 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | hbnpojogen-persistence 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.openarchitectureware.xsd.plugin.xsdBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | org.eclipse.wst.validation.validationbuilder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.eclipse.jdt.core.javanature 38 | org.eclipse.m2e.core.maven2Nature 39 | org.eclipse.wst.common.project.facet.core.nature 40 | 41 | 42 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.compliance=1.6 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.6 8 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/.settings/org.maven.ide.eclipse.prefs: -------------------------------------------------------------------------------- 1 | #Thu Feb 05 14:37:47 CET 2009 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | fullBuildGoals=process-test-resources 5 | includeModules=false 6 | resolveWorkspaceProjects=true 7 | resourceFilterGoals=process-resources resources\:testResources 8 | version=1 9 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: HbnPojoGen Persistence Plug-in 4 | Bundle-SymbolicName: com.github.wwadge.hbnpojogen.plugin.persistence;singleton:=true 5 | Bundle-Version: 1.0.0 6 | Bundle-ClassPath: . 7 | Main-Class: HbnPojoGen 8 | Export-Package: com.github.wwadge.hbnpojogen.persistence, 9 | com.github.wwadge.hbnpojogen.persistence.impl, 10 | com.github.wwadge.hbnpojogen.persistence.validator, 11 | com.github.wwadge.hbnpojogen.randomlib.data, 12 | com.github.wwadge.hbnpojogen.randomlib.data.dataGeneration 13 | Eclipse-BuddyPolicy: registered 14 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 4.0.0 5 | 6 | com.github.wwadge 7 | hbnpojogen-persistence 8 | 9 | 10 | hbnpojogen 11 | com.github.wwadge 12 | 1.5.13 13 | 14 | 15 | Hibernate POJO Generator Persistence Library 16 | 17 | 18 | 19 | org.hibernate 20 | hibernate-core 21 | 22 | 23 | 24 | commons-lang 25 | commons-lang 26 | 27 | 28 | 29 | org.springframework 30 | spring-beans 31 | 32 | 33 | 34 | org.springframework 35 | spring-context 36 | 37 | 38 | 39 | 40 | 41 | 42 | maven-jar-plugin 43 | 2.3 44 | 45 | 46 | META-INF/MANIFEST.MF 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | local-build 60 | 61 | 62 | env.ECLIPSE_HOME 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | maven-jar-plugin 71 | 72 | 73 | install 74 | 75 | jar 76 | 77 | 78 | 79 | META-INF/MANIFEST.MF 80 | 81 | 82 | ${env.ECLIPSE_HOME}\dropins 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/src/main/java/com/github/wwadge/hbnpojogen/persistence/GenericDAO.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.wwadge.hbnpojogen.persistence; 3 | 4 | import org.hibernate.Query; 5 | import org.hibernate.Session; 6 | import org.hibernate.criterion.Criterion; 7 | 8 | import java.io.Serializable; 9 | import java.util.List; 10 | 11 | 12 | /** 13 | * Generic DAO class. 14 | * 15 | * @param 16 | * @param 17 | * @author lincolns, wallacew 18 | */ 19 | public interface GenericDAO { 20 | 21 | /** 22 | * Persist the newInstance object into database. 23 | * 24 | * @param newInstance to save 25 | * @return The identifier 26 | **/ 27 | PK save(T newInstance); 28 | 29 | /** 30 | * Save or update. 31 | * 32 | * @param transientObject to save 33 | */ 34 | void saveOrUpdate(T transientObject); 35 | 36 | /** 37 | * Retrieve a persisted object with a given id from the database. 38 | * 39 | * @param id to load 40 | * @return An object of type T 41 | */ 42 | T load(PK id); 43 | 44 | /** 45 | * Retrieve a persisted object with a given id from the database. 46 | * 47 | * @param id to get 48 | * @return An object of type T 49 | */ 50 | T get(PK id); 51 | 52 | /** 53 | * Save changes made to a persistent object. 54 | * 55 | * @param transientObject object to update 56 | **/ 57 | void update(T transientObject); 58 | 59 | /** 60 | * Remove the given object from persistent storage in the database. 61 | * 62 | * @param persistentObject object to delete. 63 | **/ 64 | void delete(T persistentObject); 65 | 66 | /** 67 | * Remove the given object from persistent storage in the database. 68 | * 69 | * @param s Query to execute 70 | * @return A query object 71 | **/ 72 | Query getQuery(String s); 73 | 74 | /** 75 | * Deletes an object of a given Id. Will load the object internally so 76 | * consider using delete (T obj) directly. 77 | * 78 | * @param id Id of record 79 | */ 80 | void delete(PK id); 81 | 82 | 83 | /** 84 | * Delete object from disk. 85 | * 86 | * @param persistentObject to delete 87 | * @param session to use 88 | */ 89 | void delete(T persistentObject, Session session); 90 | 91 | /** 92 | * Deletes an object of a given Id. Will load the object internally so consider using delete (T obj) directly. 93 | * 94 | * @param id to delete 95 | * @param session to use 96 | */ 97 | void delete(PK id, Session session); 98 | 99 | /** 100 | * Loads the given Object. 101 | * 102 | * @param id to load 103 | * @param session to use 104 | * @return an object of type T 105 | */ 106 | T load(PK id, Session session); 107 | 108 | /** 109 | * Loads the given Object. 110 | * 111 | * @param id Id to load 112 | * @param session to use 113 | * @return An object of type T 114 | */ 115 | T get(PK id, Session session); 116 | 117 | /** 118 | * Save object to disk using given session. 119 | * 120 | * @param o to save 121 | * @param session to use 122 | * @return the id of the saved object 123 | */ 124 | PK save(T o, Session session); 125 | 126 | /** 127 | * Save or update given object. 128 | * 129 | * @param o item to save. 130 | * @param session to use 131 | */ 132 | void saveOrUpdate(T o, Session session); 133 | 134 | /** 135 | * Update given object. 136 | * 137 | * @param o item to update 138 | * @param session to use 139 | */ 140 | void update(T o, Session session); 141 | 142 | /** 143 | * Refreshes the object of type T. 144 | * 145 | * @param persistentObject to refresh 146 | */ 147 | void refresh(T persistentObject); 148 | 149 | /** 150 | * Get a query handle. 151 | * 152 | * @param s Query to use 153 | * @param session to use 154 | * @return Query object 155 | */ 156 | Query getQuery(String s, Session session); 157 | 158 | /** 159 | * FindByExample. 160 | * 161 | * @param exampleInstance to use 162 | * @param excludeProperty to exclude 163 | * @return A list of objects 164 | */ 165 | List findByExample(T exampleInstance, String... excludeProperty); 166 | 167 | /** 168 | * Returns a list of objects. 169 | * 170 | * @return list of objects 171 | */ 172 | List findAll(); 173 | 174 | /** 175 | * Flushes the cache of the currently-used session. 176 | */ 177 | void flush(); 178 | 179 | /** 180 | * Object to evict from cache. 181 | * 182 | * @param obj Object to evict 183 | */ 184 | void evict(Object obj); 185 | 186 | /** 187 | * Hibernate wrapper. 188 | * 189 | * @param criterion to filter. 190 | * @return list of objects 191 | */ 192 | List findByCriteria(Criterion... criterion); 193 | 194 | /** 195 | * Return the currently set class. 196 | * 197 | * @return the currently set class. 198 | */ 199 | Class getPersistentClass(); 200 | } 201 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/src/main/java/com/github/wwadge/hbnpojogen/persistence/IPojoGenEntity.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen.persistence; 2 | 3 | 4 | import java.io.Serializable; 5 | 6 | 7 | /** 8 | * All generated model classes implement this interface. 9 | * 10 | * @author wallacew 11 | * @version $Revision: 3$ 12 | */ 13 | public interface IPojoGenEntity { 14 | 15 | /** 16 | * Return the type of this class. Useful for when dealing with proxies. 17 | * 18 | * @return Defining class. 19 | */ 20 | Class getClassType(); 21 | 22 | /** 23 | * Return the id. 24 | * 25 | * @return the id. 26 | */ 27 | Serializable getId(); 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/src/main/java/com/github/wwadge/hbnpojogen/persistence/impl/CustomGeneratedId.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen.persistence.impl; 2 | 3 | import org.hibernate.dialect.Dialect; 4 | import org.hibernate.engine.SessionImplementor; 5 | import org.hibernate.id.AbstractUUIDGenerator; 6 | import org.hibernate.id.Configurable; 7 | import org.hibernate.type.Type; 8 | 9 | import java.io.Serializable; 10 | import java.lang.reflect.Method; 11 | import java.util.Properties; 12 | 13 | /** 14 | * uuid
15 | *
16 | * A custom UUID generator that returns a string from java.util.UUID, 17 | * This string will consist of only hex digits. Optionally, 18 | * the string may be generated with separators between each 19 | * component of the UUID. 20 | *

21 | * Mapping parameters supported: none 22 | * 23 | * @author wallacew 24 | */ 25 | 26 | public class CustomGeneratedId extends AbstractUUIDGenerator implements Configurable { 27 | 28 | // private String sep = ""; 29 | 30 | /** 31 | * Generate function. 32 | * 33 | * @param session Session handle 34 | * @param obj obj type 35 | * @return Serializable object 36 | */ 37 | @SuppressWarnings("unused") 38 | public Serializable generate(SessionImplementor session, Object obj) { 39 | Serializable result = null; 40 | 41 | // if user has set the id manually, don't change it. 42 | try { 43 | Class clazz = obj.getClass(); 44 | Method idMethod = clazz.getMethod("getId"); 45 | result = (Serializable) idMethod.invoke(obj); 46 | } catch (Exception e) { 47 | // do nothing 48 | } 49 | 50 | if (result == null) { 51 | result = java.util.UUID.randomUUID().toString(); 52 | } 53 | 54 | return result; 55 | } 56 | 57 | /** 58 | * Currently unused. 59 | * 60 | * @param type hibernate config 61 | * @param params hibernate config 62 | * @param d dialect to use 63 | */ 64 | @SuppressWarnings("unused") 65 | public void configure(Type type, Properties params, Dialect d) { 66 | // sep = PropertiesHelper.getString("separator", params, ""); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/src/main/java/com/github/wwadge/hbnpojogen/persistence/impl/HibernateUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen.persistence.impl; 2 | 3 | 4 | import com.github.wwadge.hbnpojogen.persistence.IPojoGenEntity; 5 | import org.hibernate.SessionFactory; 6 | import org.hibernate.proxy.HibernateProxy; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | * Wrapper for narrowCast function. 12 | * 13 | * @author wallacew 14 | */ 15 | 16 | @Component 17 | public class HibernateUtils { 18 | 19 | private static SessionFactory sessionFactory; 20 | 21 | @SuppressWarnings("unchecked") 22 | public static T narrowCast(T obj) { 23 | T result = obj; 24 | 25 | if (obj != null && obj instanceof HibernateProxy) { 26 | result = (T) ((HibernateProxy) obj).getHibernateLazyInitializer().getImplementation(); 27 | } 28 | 29 | return result; 30 | } 31 | 32 | 33 | @Autowired 34 | public void setSessionFactory(SessionFactory sf) { 35 | HibernateUtils.sessionFactory = sf; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/src/main/java/com/github/wwadge/hbnpojogen/persistence/impl/IDPresentAwareGenerator.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen.persistence.impl; 2 | 3 | 4 | import org.hibernate.engine.SessionImplementor; 5 | import org.hibernate.id.IdentityGenerator; 6 | 7 | import java.io.Serializable; 8 | import java.lang.reflect.Method; 9 | 10 | 11 | /** 12 | *
13 | * A custom generator that behaves as follows: If id is null (or zero to workaround a hibernate bug), behave as 14 | * if generator was set to AUTO (i.e. get the autoincrement value from the database. Otherwise use the provided ID. 15 | *

16 | * Mapping parameters supported: none 17 | * 18 | * @author wallacew 19 | */ 20 | public class IDPresentAwareGenerator extends IdentityGenerator { 21 | 22 | @Override 23 | public Serializable generate(SessionImplementor session, Object obj) { 24 | Serializable result = null; 25 | 26 | // if user has set the id manually, don't change it. 27 | try { 28 | Class clazz = obj.getClass(); 29 | Method idMethod = clazz.getMethod("getId"); 30 | result = (Serializable) idMethod.invoke(obj); 31 | } catch (Exception e) { 32 | // do nothing 33 | } 34 | 35 | // id not set (or set to 0 due to hibernate bug workaround), proceed 36 | // as if generator was set to AUTO 37 | if (result == null || (result.toString().equals("0"))) { 38 | 39 | return super.generate(session, obj); 40 | } 41 | 42 | return result; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/src/main/java/com/github/wwadge/hbnpojogen/persistence/impl/StringValuedEnum.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen.persistence.impl; 2 | 3 | /** 4 | * Utility class designed to allow dynamic fidding and manipulation of Enum 5 | * instances which hold a string value. 6 | * 7 | * @author unknown 8 | */ 9 | public interface StringValuedEnum { 10 | 11 | /** 12 | * Current string value stored in the enum. 13 | * 14 | * @return string value. 15 | */ 16 | String getValue(); 17 | 18 | } -------------------------------------------------------------------------------- /hbnpojogen-persistence/src/main/java/com/github/wwadge/hbnpojogen/persistence/impl/StringValuedEnumReflect.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Utility class designed to inspect StringValuedEnums. 3 | * 4 | * @author wallacew 5 | */ 6 | 7 | package com.github.wwadge.hbnpojogen.persistence.impl; 8 | 9 | 10 | public class StringValuedEnumReflect { 11 | 12 | /** 13 | * Don't let anyone instantiate this class. 14 | * @throws UnsupportedOperationException Always. 15 | */ 16 | private StringValuedEnumReflect() { 17 | throw new UnsupportedOperationException("This class must not be instantiated."); 18 | } 19 | 20 | /** 21 | * All Enum constants (instances) declared in the specified class. 22 | * @param enumClass Class to reflect 23 | * @param Type 24 | * @return Array of all declared EnumConstants (instances). 25 | */ 26 | @SuppressWarnings("unchecked") 27 | private static T[] 28 | getValues(Class enumClass) { 29 | return enumClass.getEnumConstants(); 30 | } 31 | 32 | /** 33 | * All possible string values of the string valued enum. 34 | * @param enumClass Class to reflect. 35 | * @param Type 36 | * @return Available string values. 37 | */ 38 | @SuppressWarnings("unchecked") 39 | public static String[] 40 | getStringValues(Class enumClass) { 41 | T[] values = getValues(enumClass); 42 | String[] result = new String[values.length]; 43 | for (int i = 0; i < values.length; i++) { 44 | result[i] = values[i].getValue(); 45 | } 46 | return result; 47 | } 48 | 49 | /** 50 | * Name of the enum instance which hold the especified string value. 51 | * If value has duplicate enum instances than returns the first occurency. 52 | * @param enumClass Class to inspect. 53 | * @param value String. 54 | * @param Type 55 | * @return name of the enum instance. 56 | */ 57 | @SuppressWarnings("unchecked") 58 | public static String 59 | getNameFromValue(Class enumClass, Object value) { 60 | T[] values = getValues(enumClass); 61 | for (int i = 0; i < values.length; i++) { 62 | if (values[i].getValue().toString().equals(value.toString())) { 63 | return values[i].name(); 64 | } 65 | } 66 | return ""; 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /hbnpojogen-persistence/src/main/java/com/github/wwadge/hbnpojogen/persistence/validator/Mandatory.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen.persistence.validator; 2 | 3 | 4 | import java.lang.annotation.Documented; 5 | import java.lang.annotation.Inherited; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.Target; 8 | 9 | import static java.lang.annotation.ElementType.FIELD; 10 | import static java.lang.annotation.ElementType.METHOD; 11 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 12 | 13 | 14 | /** 15 | * Designates a property that is required to have a value. It cannot be null or 16 | * empty. The default message is "validator.required" which is assumed to exist 17 | * in the expected resource bundle ValidatorMessages.properties. 18 | * 19 | * @author alexiaa 20 | * @version $Revision: 1$ 21 | */ 22 | @Documented 23 | @Target({METHOD, FIELD}) 24 | @Retention(RUNTIME) 25 | @Inherited 26 | @Deprecated 27 | public @interface Mandatory { 28 | /** 29 | * Default message. 30 | */ 31 | String message() default "Property marked as mandatory and cannot be left blank."; 32 | } 33 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/src/main/java/com/github/wwadge/hbnpojogen/randomlib/data/CountryCodes.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen.randomlib.data; 2 | 3 | /** 4 | * Static country codes data. 5 | * 6 | * @author robertam 7 | */ 8 | public class CountryCodes { 9 | 10 | 11 | /** 12 | * Static numeric Data for Country Codes. 13 | */ 14 | private static final String[] countryCodesNum = { 15 | "004", "008", "010", "012", "016", "020", "024", "028", "031", "032", "036", "040", "044", "048", "050", "051", 16 | "052", "056", "060", "064", "068", "070", "072", "074", "076", "084", "086", "090", "092", "096", "100", "104", 17 | "108", "112", "116", "120", "124", "132", "136", "140", "144", "148", "152", "156", "158", "162", "166", "170", 18 | "174", "175", "178", "180", "184", "188", "191", "192", "196", "203", "204", "208", "212", "214", "218", "222", 19 | "226", "231", "232", "233", "234", "238", "239", "242", "246", "248", "250", "254", "258", "260", "262", "266", 20 | "268", "270", "275", "276", "288", "292", "296", "300", "304", "308", "312", "316", "320", "324", "328", "332", 21 | "334", "336", "340", "344", "348", "352", "356", "360", "364", "368", "372", "376", "380", "384", "388", "392", 22 | "398", "400", "404", "408", "410", "414", "417", "418", "422", "426", "428", "430", "434", "438", "440", "442", 23 | "446", "450", "454", "458", "462", "466", "470", "474", "478", "480", "484", "492", "496", "498", "500", "504", 24 | "508", "512", "516", "520", "524", "528", "530", "533", "540", "548", "554", "558", "562", "566", "570", "574", 25 | "578", "580", "581", "583", "584", "585", "586", "591", "598", "600", "604", "608", "612", "616", "620", "624", 26 | "626", "630", "634", "638", "642", "643", "646", "654", "659", "660", "662", "666", "670", "674", "678", "682", 27 | "686", "690", "694", "702", "703", "704", "705", "706", "710", "716", "724", "732", "736", "740", "744", "748", 28 | "752", "756", "760", "762", "764", "768", "772", "776", "780", "784", "788", "792", "795", "796", "798", "800", 29 | "804", "807", "818", "826", "830", "833", "834", "840", "850", "854", "858", "860", "862", "876", "882", "887", 30 | "891", "894" 31 | }; 32 | 33 | 34 | /** 35 | * Static acronym Data for Country Codes. 36 | */ 37 | private static final String[] countryCodesAc = { 38 | "GB", "US", "CA", "MX", "BM", "SE", "IT", "A2", "PR", "IN", "VI", "DE", 39 | "IR", "BO", "NG", "NL", "FR", "IL", "ES", "PA", "CL", "BS", "AR", "DM", 40 | "BE", "IE", "BZ", "BR", "CH", "ZA", "EG", "SC", "TZ", "KM", "RW", "DZ", 41 | "GH", "CI", "SZ", "CM", "MG", "KE", "AO", "NA", "MA", "SL", "GA", "MU", 42 | "TG", "LY", "SN", "SD", "UG", "ZW", "MZ", "MW", "ZM", "BW", "LR", "CD", 43 | "BJ", "TN", "JP", "EU", "AU", "TH", "CN", "MY", "PK", "NZ", "KR", "HK", 44 | "SG", "BD", "ID", "PH", "TW", "AF", "VN", "VU", "NC", "BN", "AP", "GR", 45 | "SA", "PL", "CZ", "RU", "CY", "NO", "AT", "UA", "TJ", "DK", "PT", "TR", 46 | "GE", "BY", "IQ", "AM", "LB", "MD", "BG", "FI", "OM", "LV", "KZ", "EE", 47 | "SK", "JO", "HU", "KW", "AL", "LT", "SM", "RO", "RS", "HR", "LU", "IS", 48 | "LI", "CR", "MK", "MT", "GM", "SI", "FK", "AZ", "MC", "HT", "GU", "JM", 49 | "FM", "EC", "CO", "PE", "KY", "GP", "HN", "YE", "VG", "LC", "SY", "NI", 50 | "DO", "AN", "GT", "VE", "BA", "HM", "UY", "SV", "AE", "TT", "LK", "BV", 51 | "MH", "BH", "CK", "GI", "PY", "AG", "LS", "KN", "WS", "PW", "QA", "KH", 52 | "AI", "AS", "TC", "MP", "UZ", "MO", "UM", "RE", "GY", "CU", "CG", "A1", 53 | "BB", "LA", "SR", "AW", "FJ", "MS", "GD", "VC", "NP", "NE", "KG", "ME", 54 | "TD", "FO", "SO", "ML", "PS", "BI", "GN", "ET", "MR", "MQ", "VA", "TM", 55 | "YT", "BF", "AD", "AQ", "GL", "WF", "PG", "MN", "PF", "MV", "GQ", "CF", 56 | "ER", "GW", "DJ", "CV", "ST", "GF", "SB", "TV", "KI", "TO", "IO", "NU", 57 | "TK", "NR", "BT", "NF", "MM", "KP" 58 | }; 59 | 60 | /** 61 | * Return the i'th element of the country codes ac array. 62 | * 63 | * @param i the element to return 64 | * @return Return the i'th element of the country codes ac array 65 | */ 66 | public static String getCountryCodesAc(int i) { 67 | return getCountryCode(countryCodesAc, i); 68 | } 69 | 70 | /** 71 | * Return the i'th element of the country codes num array. 72 | * 73 | * @param i the element to return 74 | * @return Return the i'th element of the country codes num array 75 | */ 76 | public static String getCountryCodesNum(int i) { 77 | return getCountryCode(countryCodesNum, i); 78 | } 79 | 80 | /** 81 | * Return the length of the country codes num array. 82 | * 83 | * @return the length of the country codes num array 84 | */ 85 | public static int getCountryCodesNumLength() { 86 | return getCountryCodeLength(countryCodesNum); 87 | } 88 | 89 | /** 90 | * Return the length of the country codes ac array. 91 | * 92 | * @return the length of the country codes ac array 93 | */ 94 | public static int getCountryCodesAcLength() { 95 | return getCountryCodeLength(countryCodesAc); 96 | } 97 | 98 | /** 99 | * Return a country code. 100 | * 101 | * @param i index 102 | * @param ar array to use 103 | * @return a valid country code 104 | */ 105 | public static String getCountryCode(String[] ar, int i) { 106 | if (i > ar.length) { 107 | throw new IndexOutOfBoundsException(); 108 | } 109 | return ar[i]; 110 | } 111 | 112 | /** 113 | * Return the length of the array. 114 | * 115 | * @param ar array to use 116 | * @return max no of country code array length 117 | */ 118 | public static int getCountryCodeLength(String[] ar) { 119 | return ar.length; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /hbnpojogen-persistence/src/main/java/com/github/wwadge/hbnpojogen/randomlib/data/dataGeneration/ComplexDataTypes.java: -------------------------------------------------------------------------------- 1 | package com.github.wwadge.hbnpojogen.randomlib.data.dataGeneration; 2 | 3 | import com.github.wwadge.hbnpojogen.randomlib.data.CountryCodes; 4 | 5 | import java.util.Locale; 6 | import java.util.Random; 7 | 8 | 9 | /** 10 | * A class providing methods for generating random data for complex data types. 11 | * 12 | * @author robertam 13 | */ 14 | public class ComplexDataTypes { 15 | 16 | /** 17 | * Random Number Generator. 18 | */ 19 | public final static Random generator = new Random(); 20 | 21 | /** 22 | * Generates a random ID for Client or Provider. 23 | * 24 | * @return A random ID for Client or Provider 25 | */ 26 | public static Long generateID() { 27 | long id = generator.nextLong(); 28 | 29 | while (id <= 0) { 30 | id = generator.nextLong(); 31 | } 32 | 33 | return id; 34 | } 35 | 36 | /** 37 | * Generates a random IP. 38 | * 39 | * @return an Ip Address 40 | */ 41 | public static String generateRandomIp() { 42 | String ip = generator.nextInt(254) + "." + generator.nextInt(254) + "." + generator.nextInt(254) + "." + generator.nextInt(254); 43 | return ip; 44 | } 45 | 46 | /** 47 | * Generates a random URL. 48 | * 49 | * @return a random url 50 | */ 51 | public static String generateRandomUrl() { 52 | StringBuffer sb = new StringBuffer(); 53 | sb.append("http://www."); 54 | sb.append(BasicDataGenerator.generateRandomStringChar(10).toLowerCase(Locale.getDefault())); 55 | sb.append(".com"); 56 | return sb.toString(); 57 | } 58 | 59 | /** 60 | * Returns a random country code in the form of 3 digits. 61 | * 62 | * @return 3-digit country code 63 | */ 64 | public static Integer generateNumericCountryCode() { 65 | int choice = generator.nextInt(CountryCodes.getCountryCodesNumLength()); 66 | return Integer.parseInt(CountryCodes.getCountryCodesNum(choice)); 67 | } 68 | 69 | /** 70 | * Returns a random country code in the form of 2 letters. 71 | * 72 | * @return 2-letter country code 73 | */ 74 | public static String generateCountryCode() { 75 | int choice = generator.nextInt(CountryCodes.getCountryCodesAcLength()); 76 | return CountryCodes.getCountryCodesAc(choice); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /inflector/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /inflector/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | inflector 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.openarchitectureware.xsd.plugin.xsdBuilder 15 | 16 | 17 | 18 | 19 | org.maven.ide.eclipse.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.maven.ide.eclipse.maven2Nature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /inflector/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jun 18 11:31:09 CEST 2009 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.5 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.5 13 | -------------------------------------------------------------------------------- /inflector/.settings/org.maven.ide.eclipse.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jun 18 11:27:55 CEST 2009 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | fullBuildGoals=process-test-resources 5 | includeModules=false 6 | resolveWorkspaceProjects=true 7 | resourceFilterGoals=process-resources resources\:testResources 8 | skipCompilerPlugin=true 9 | version=1 10 | -------------------------------------------------------------------------------- /inflector/bin/org/jvnet/inflector/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | Classes for inflecting natural language words, especially for forming plurals. 4 |

5 | -------------------------------------------------------------------------------- /inflector/bin/org/jvnet/inflector/rule/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | Classes for specifying inflections using rules. 4 |

5 | -------------------------------------------------------------------------------- /inflector/bin/overview.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Inflector - User Guide 4 | 5 | 6 | 7 | 8 | 9 |

10 | Inflector provides an API for forming the plurals of nouns. Here's a simple example: 11 |

12 | 13 |
System.out.println(Noun.pluralOf("loaf"));
14 | 15 |

16 | This will print 17 |

18 | 19 |
loaves
20 | 21 |

22 | to the console. 23 |

24 | 25 |

26 | It's handy to use Java 5 static imports to make this more readable, 27 | particularly if you are forming lots of plurals. 28 |

29 | 30 |
import static org.jvnet.inflector.Noun.pluralOf;
 31 | ...
 32 | System.out.println(pluralOf("loaf"));
 33 | 
34 | 35 |

Nouns

36 | 37 |

38 | It is often useful to use a {@link java.util.Formatter}. For example, 39 |

40 | 41 |
System.out.printf("I bought 10 %s.", pluralOf("loaf"));
 42 | 
43 | 44 |

45 | prints 46 |

47 | 48 |
I bought 10 loaves.
49 | 50 |

51 | Of course, you can parameterize the number, as follows. 52 |

53 | 54 |
int n = 10;
 55 | System.out.printf("I bought %d %s.", n, pluralOf("loaf", n));
 56 | 
57 | 58 |

59 | Notice that you pass the number into the pluralOf method to make sure the noun agrees. 60 | For example, if n = 1 in the previous example, it would correctly print 61 |

62 | 63 |
I bought 1 loaf.
64 | 65 |

Internationalization

66 | 67 |

68 | The examples so far use the default locale to determine the pluralization algorithm to use. You can explictly set 69 | the locale to use by passing another argument: 70 |

71 | 72 |
System.out.println(pluralOf("pagnotta", Locale.ITALIAN));
 73 | 
74 | 75 |

76 | prints 77 |

78 | 79 |
pagnotte
80 | 81 |

Custom Pluralization

82 | 83 |

84 | The pluralization algorithms that come with Inflector may not meet your needs. Perhaps there is no algorithm for your language, 85 | or perhaps the rules don't fit the usage that is appropriate for your application. The English 86 | pluralizer, for example, is fairly modern: it does not support many classical rules that are rare nowadays. 87 |

88 | 89 |

90 | In this case it is straightforward to write your own pluralizer, or simply extend another one to override some of its rules. 91 | The follow code overrides the plural for box to boxen by using a {@link org.jvnet.inflector.rule.RegexReplacementRule}: 92 |

93 | 94 |
List<Rule> customRules = new ArrayList<Rule>();
 95 | customRules.add(new RegexReplacementRule("(?i)(.*)box", "$1boxen"));
 96 | Pluralizer customPluralizer = new RuleBasedPluralizer(customRules, Locale.ENGLISH, Noun.pluralizer(Locale.ENGLISH));
 97 | System.out.println(pluralOf("box"));
 98 | System.out.println(pluralOf("box", customPluralizer));
 99 | System.out.println(pluralOf("chatterbox", customPluralizer));
100 | 
101 | 102 |

103 | This prints 104 |

105 | 106 |
boxes
107 | boxen
108 | chatterboxen
109 | 110 |

111 | If you are interested in writing more complex rules, there are many other implementations of 112 | {@link org.jvnet.inflector.Rule} in the {@link org.jvnet.inflector.rule} package. 113 |

114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /inflector/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | ================================= WARNING ================================ 105 | Junit isn't present in your ${ANT_HOME}/lib directory. Tests not executed. 106 | ========================================================================== 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /inflector/maven.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /inflector/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | Inflector 5 | jar 6 | net.java.dev.inflector 7 | inflector 8 | 0.7.0-patched 9 | 10 | 11 | Tom White 12 | http://www.tiling.org/ 13 | 14 | 15 | 2006 16 | 17 | 18 | Inflector is a Java API for forming plurals of 19 | words. The goal of the project is to provide a high-quality, 20 | easy-to-use API that is localizable to support any language. 21 | 22 | 23 | 24 | 25 | 26 | org.easymock 27 | easymock 28 | 2.4 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | maven-compiler-plugin 37 | 2.0.1 38 | 39 | 1.6 40 | 1.6 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /inflector/project.properties: -------------------------------------------------------------------------------- 1 | maven.javanet.project=inflector 2 | 3 | maven.changelog.factory=org.apache.maven.svnlib.SvnChangeLogFactory 4 | 5 | maven.javadoc.excludepackagenames=org.jvnet.inflector.lang.* 6 | maven.javadoc.links=http://java.sun.com/j2se/1.5.0/docs/api/ 7 | maven.javadoc.overview=src/main/java/overview.html -------------------------------------------------------------------------------- /inflector/src/main/java/org/jvnet/inflector/Noun.java: -------------------------------------------------------------------------------- 1 | package org.jvnet.inflector; 2 | import java.io.Serializable; 3 | import java.util.Locale; 4 | 5 | /** 6 | *

7 | * A Noun represents the grammatical part of speech that refers to 8 | * a person, place, thing, event, substance, quality or idea. 9 | *

10 | *

11 | * This class contains a number of static convenience methods ({@link #pluralOf(String)} for forming plurals. 12 | *

13 | * @author Tom White 14 | */ 15 | public class Noun implements Serializable{ 16 | 17 | /** 18 | *

19 | * Creates a new {@link Pluralizer} instance for the default locale. 20 | *

21 | * @return a pluralizer instance for the default locale 22 | */ 23 | public static Pluralizer pluralizer() { 24 | return pluralizer(Locale.getDefault()); 25 | } 26 | 27 | /** 28 | *

29 | * Creates a new {@link Pluralizer} instance for the specified locale. 30 | *

31 | * @param locale the locale specifying the language of the pluralizer 32 | * @return a pluralizer instance for the specified locale, or null if there is none for this locale 33 | */ 34 | public static Pluralizer pluralizer(Locale locale) { 35 | String className = "org.jvnet.inflector.lang." + locale.getLanguage() + ".NounPluralizer"; 36 | try { 37 | Class c = Class.forName(className); 38 | return (Pluralizer) c.newInstance(); 39 | } catch (ClassNotFoundException e) { 40 | return null; 41 | } catch (InstantiationException e) { 42 | throw new RuntimeException("Problem instantiating " + className, e); 43 | } catch (IllegalAccessException e) { 44 | throw new RuntimeException("Problem instantiating " + className, e); 45 | } 46 | } 47 | 48 | /** 49 | *

50 | * Converts a noun to its plural form using the {@link Pluralizer} for the default locale. 51 | *

52 | *

53 | * The return value is not defined if this method is passed a plural form. 54 | *

55 | * @param word a singular form 56 | * @return the plural form 57 | */ 58 | public static String pluralOf(String word) { 59 | return pluralOf(word, pluralizer()); 60 | } 61 | 62 | /** 63 | *

64 | * Converts a noun to its plural form for the given number of instances 65 | * using the {@link Pluralizer} for the default locale. 66 | *

67 | *

68 | * The return value is not defined if this method is passed a plural form. 69 | *

70 | * @param word a singular form 71 | * @param number the number of objects being referred to in the plural 72 | * @return the plural form 73 | */ 74 | public static String pluralOf(String word, int number) { 75 | return pluralOf(word, number, pluralizer()); 76 | } 77 | 78 | /** 79 | *

80 | * Converts a noun to its plural form using the {@link Pluralizer} for the given locale. 81 | *

82 | *

83 | * The return value is not defined if this method is passed a plural form. 84 | *

85 | * @param word a singular form 86 | * @param locale the locale specifying the language of the pluralizer 87 | * @return the plural form 88 | */ 89 | public static String pluralOf(String word, Locale locale) { 90 | return pluralOf(word, pluralizer(locale)); 91 | } 92 | 93 | /** 94 | *

95 | * Converts a noun to its plural form for the given number of instances 96 | * using the {@link Pluralizer} for the given locale. 97 | *

98 | *

99 | * The return value is not defined if this method is passed a plural form. 100 | *

101 | * @param word a singular form 102 | * @param number the number of objects being referred to in the plural 103 | * @param locale the locale specifying the language of the pluralizer 104 | * @return the plural form 105 | */ 106 | public static String pluralOf(String word, int number, Locale locale) { 107 | return pluralOf(word, number, pluralizer(locale)); 108 | } 109 | 110 | /** 111 | *

112 | * Converts a noun to its plural form using the given {@link Pluralizer}. 113 | *

114 | *

115 | * The return value is not defined if this method is passed a plural form. 116 | *

117 | * @param word a singular form 118 | * @param pluralizer a noun pluralizer 119 | * @return the plural form 120 | */ 121 | public static String pluralOf(String word, Pluralizer pluralizer) { 122 | return pluralizer == null ? null : pluralizer.pluralize(word); 123 | } 124 | 125 | /** 126 | *

127 | * Converts a noun to its plural form for the given number of instances 128 | * using the given {@link Pluralizer}. 129 | *

130 | *

131 | * The return value is not defined if this method is passed a plural form. 132 | *

133 | * @param word a singular form 134 | * @param number the number of objects being referred to in the plural 135 | * @param pluralizer a noun pluralizer 136 | * @return the plural form 137 | */ 138 | public static String pluralOf(String word, int number, Pluralizer pluralizer) { 139 | return pluralizer == null ? null : pluralizer.pluralize(word, number); 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /inflector/src/main/java/org/jvnet/inflector/Pluralizer.java: -------------------------------------------------------------------------------- 1 | package org.jvnet.inflector; 2 | 3 | /** 4 | *

5 | * Pluralizer converts singular word forms to their plural forms. 6 | * Methods that are passed null must throw 7 | * a {@link java.lang.NullPointerException}. 8 | *

9 | *

10 | * Implementations of this interface must be safe for use by multiple concurrent threads. 11 | *

12 | * @author Tom White 13 | */ 14 | public interface Pluralizer { 15 | 16 | /** 17 | *

18 | * Converts a word to its plural form. 19 | *

20 | *

21 | * The return value is not defined if this method is passed a plural form. 22 | *

23 | * @param word a singular form 24 | * @return the plural form 25 | */ 26 | public String pluralize(String word); 27 | 28 | /** 29 | *

30 | * Converts a word to its plural form for the given number of instances. 31 | * Some languages (such as Polish) 32 | * have different plural forms depending on the number 33 | * of things being referred to. 34 | *

35 | *

36 | * The return value is not defined if this method is passed a plural form. 37 | *

38 | * @param word a singular form 39 | * @param number the number of objects being referred to in the plural 40 | * @return the plural form 41 | */ 42 | public String pluralize(String word, int number); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /inflector/src/main/java/org/jvnet/inflector/Rule.java: -------------------------------------------------------------------------------- 1 | package org.jvnet.inflector; 2 | 3 | /** 4 | *

5 | * A Rule represents how a word changes from one form to another. 6 | *

7 | *

8 | * Implementations of this interface must be safe for use by multiple concurrent threads in order to 9 | * satisfy the contract of {@link Pluralizer}. 10 | *

11 | * @author Tom White 12 | */ 13 | public interface Rule { 14 | /** 15 | *

16 | * Tests to see if this rule applies for the given word. 17 | *

18 | * @param word the word that is being tested 19 | * @return true if this rule should be applied, false otherwise 20 | */ 21 | public boolean applies(String word); 22 | 23 | /** 24 | *

25 | * Applies this rule to the word, and transforming it into a new form. 26 | *

27 | * @param word the word to apply this rule to 28 | * @return the transformed word 29 | */ 30 | public String apply(String word); 31 | } 32 | -------------------------------------------------------------------------------- /inflector/src/main/java/org/jvnet/inflector/RuleBasedPluralizer.java: -------------------------------------------------------------------------------- 1 | package org.jvnet.inflector; 2 | 3 | import java.io.Serializable; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.Locale; 7 | import java.util.regex.Matcher; 8 | import java.util.regex.Pattern; 9 | 10 | /** 11 | *

12 | * An implementation of {@link Pluralizer} that is implemented using an ordered list of {@link Rule}s. 13 | * It is possible to specify a fallback {@link Pluralizer} that is invoked if none of the rules match. 14 | * This makes it easy to override some rules of another {@link Pluralizer}. 15 | *

16 | *

17 | * This class also preserves leading and trailing whitespace, so individual rules don't need to 18 | * explicitly handle it. 19 | * Case is also preserved; that is, the output of all uppercase input is automatically uppercased, and 20 | * the output of titlecase input is automatically titlecased. 21 | * This means rules can act in a case-insensitive manner. 22 | *

23 | *

24 | * Instances of this class are safe for multiple concurrent threads. 25 | *

26 | * @author Tom White 27 | */ 28 | public class RuleBasedPluralizer implements Pluralizer, Serializable{ 29 | 30 | /** */ 31 | private static final long serialVersionUID = 7466676432551660465L; 32 | 33 | static class IdentityPluralizer implements Pluralizer, Serializable { 34 | /** */ 35 | private static final long serialVersionUID = -794888679795568207L; 36 | public String pluralize(String word) { 37 | return word; 38 | } 39 | public String pluralize(String word, int number) { 40 | return word; 41 | } 42 | } 43 | 44 | private static final Pluralizer IDENTITY_PLURALIZER = new IdentityPluralizer(); 45 | 46 | private List rules; 47 | private Locale locale; 48 | private Pluralizer fallbackPluralizer; 49 | 50 | /** 51 | *

52 | * Constructs a pluralizer with an empty list of rules. 53 | * Use the setters to configure. 54 | *

55 | */ 56 | @SuppressWarnings("unchecked") 57 | public RuleBasedPluralizer() { 58 | this(Collections.EMPTY_LIST, Locale.getDefault()); 59 | } 60 | 61 | /** 62 | *

63 | * Constructs a pluralizer that uses a list of rules then an identity {@link Pluralizer} 64 | * if none of the rules match. 65 | * This is useful to build your own {@link Pluralizer} from scratch. 66 | *

67 | * @param rules the rules to apply in order 68 | * @param locale the locale specifying the language of the pluralizer 69 | */ 70 | public RuleBasedPluralizer(List rules, Locale locale) { 71 | this(rules, locale, IDENTITY_PLURALIZER); 72 | } 73 | 74 | /** 75 | *

76 | * Constructs a pluralizer that uses first a list of rules then a fallback {@link Pluralizer}. 77 | * This is useful to override the behaviour of an existing {@link Pluralizer}. 78 | *

79 | * @param rules the rules to apply in order 80 | * @param locale the locale specifying the language of the pluralizer 81 | * @param fallbackPluralizer the pluralizer to use if no rules match 82 | */ 83 | public RuleBasedPluralizer(List rules, Locale locale, Pluralizer fallbackPluralizer) { 84 | this.rules = rules; 85 | this.locale = locale; 86 | this.fallbackPluralizer = fallbackPluralizer; 87 | } 88 | 89 | public Pluralizer getFallbackPluralizer() { 90 | return fallbackPluralizer; 91 | } 92 | 93 | public void setFallbackPluralizer(Pluralizer fallbackPluralizer) { 94 | this.fallbackPluralizer = fallbackPluralizer; 95 | } 96 | 97 | public Locale getLocale() { 98 | return locale; 99 | } 100 | 101 | public void setLocale(Locale locale) { 102 | this.locale = locale; 103 | } 104 | 105 | public List getRules() { 106 | return rules; 107 | } 108 | 109 | public void setRules(List rules) { 110 | this.rules = rules; 111 | } 112 | 113 | /** 114 | *

115 | * Converts a noun or pronoun to its plural form. 116 | *

117 | *

118 | * This method is equivalent to calling pluralize(word, 2). 119 | *

120 | *

121 | * The return value is not defined if this method is passed a plural form. 122 | *

123 | * @param word a singular noun 124 | * @return the plural form of the noun 125 | */ 126 | public String pluralize(String word) { 127 | return pluralize(word, 2); 128 | } 129 | 130 | /** 131 | *

132 | * Converts a noun or pronoun to its plural form for the given number of instances. 133 | * If number is 1, word is returned unchanged. 134 | *

135 | *

136 | * The return value is not defined if this method is passed a plural form. 137 | *

138 | * @param word a singular noun 139 | * @param number the number of objects being referred to in the plural 140 | * @return the plural form of the noun 141 | */ 142 | public String pluralize(String word, int number) { 143 | if (number == 1) { 144 | return word; 145 | } 146 | 147 | Pattern pattern = Pattern.compile("\\A(\\s*)(.+?)(\\s*)\\Z"); 148 | Matcher matcher = pattern.matcher(word); 149 | if (matcher.matches()) { 150 | String pre = matcher.group(1); 151 | String trimmedWord = matcher.group(2); 152 | String post = matcher.group(3); 153 | String plural = pluralizeInternal(trimmedWord); 154 | if (plural == null) { 155 | return fallbackPluralizer.pluralize(word, number); 156 | } 157 | return pre + postProcess(trimmedWord, plural) + post; 158 | } 159 | return word; 160 | 161 | } 162 | 163 | /** 164 | *

165 | * Goes through the rules in turn until a match is found at which point the rule is applied 166 | * and the result returned. 167 | * If no rule matches, returns null. 168 | *

169 | * @param word a singular noun 170 | * @return the plural form of the noun, or null if no rule matches 171 | */ 172 | protected String pluralizeInternal(String word) { 173 | for (Rule rule : rules) { 174 | if (rule.applies(word)) { 175 | return rule.apply(word); 176 | } 177 | } 178 | return null; 179 | } 180 | 181 | /** 182 | *

183 | * Apply processing to pluralizedWord. This implementation ensures 184 | * the case of the plural is consistent with the case of the input word. 185 | *

186 | *

187 | * If trimmedWord is all uppercase, then pluralizedWord 188 | * is uppercased. 189 | * If trimmedWord is titlecase, then pluralizedWord 190 | * is titlecased. 191 | *

192 | * @param trimmedWord the input word, with leading and trailing whitespace removed 193 | * @param pluralizedWord the pluralized word 194 | * @return the pluralizedWord after processing 195 | */ 196 | protected String postProcess(String trimmedWord, String pluralizedWord) { 197 | if (trimmedWord.matches("^\\p{Lu}+$")) { 198 | return pluralizedWord.toUpperCase(locale); 199 | } else if (trimmedWord.matches("^\\p{Lu}.*")) { 200 | return pluralizedWord.substring(0, 1).toUpperCase(locale) + pluralizedWord.substring(1); 201 | } 202 | return pluralizedWord; 203 | } 204 | 205 | } 206 | -------------------------------------------------------------------------------- /inflector/src/main/java/org/jvnet/inflector/lang/it/NounPluralizer.java: -------------------------------------------------------------------------------- 1 | package org.jvnet.inflector.lang.it; 2 | 3 | import static org.jvnet.inflector.rule.AbstractRegexReplacementRule.disjunction; 4 | import static org.jvnet.inflector.rule.IrregularMappingRule.toMap; 5 | 6 | import java.io.Serializable; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | import java.util.Locale; 10 | import java.util.Map; 11 | 12 | import org.jvnet.inflector.Pluralizer; 13 | import org.jvnet.inflector.Rule; 14 | import org.jvnet.inflector.RuleBasedPluralizer; 15 | import org.jvnet.inflector.rule.CategoryInflectionRule; 16 | import org.jvnet.inflector.rule.IrregularMappingRule; 17 | import org.jvnet.inflector.rule.RegexReplacementRule; 18 | import org.jvnet.inflector.rule.SuffixInflectionRule; 19 | 20 | /** 21 | *

22 | * A {@link Pluralizer} for Italian nouns. 23 | *

24 | *

25 | * Instances of this class are safe for multiple concurrent threads. 26 | *

27 | *

28 | * This code is based on the rules for plurals described in 29 | * BBC Italian Grammar, 30 | * by Alwena Lamping. 31 | *

32 | *

33 | * This is not a full implementation since most exceptional categories (e.g. irregular nouns, 34 | * words ending -co which change to -ci, etc.) are very incomplete. 35 | * Also, pronouns are not supported. 36 | *

37 | * @author Tom White 38 | */ 39 | public class NounPluralizer extends RuleBasedPluralizer implements Serializable { 40 | 41 | /** */ 42 | private static final long serialVersionUID = 4260156287305105361L; 43 | 44 | private static final Map IRREGULAR_NOUNS = toMap(new String[][]{ 45 | { "moglie", "mogli" }, 46 | { "uovo", "uova" }, 47 | { "lenzuolo", "lenzuola" }, 48 | { "paio", "paia" }, 49 | { "braccio", "braccia" }, 50 | { "dito", "dita" }, 51 | { "centinaio", "centinaia" }, 52 | { "uomo", "uomini" }, 53 | { "dio", "dei" }, 54 | { "collega", "colleghi" }, // assume male form 55 | { "atleta", "atleti" }, // assume male form 56 | }); 57 | 58 | private static final String[] CATEGORY_UNINFLECTED_NOUNS = { 59 | "radio", "foto", "moto", // feminine word ending in -o 60 | "computer", "chef", "hostess", // loan words 61 | }; 62 | 63 | private static final String[] CATEGORY_MA_MA_RULE = { 64 | // words ending -ma which are uninflected 65 | "cinema", "clima" 66 | }; 67 | 68 | private static final String[] CATEGORY_MA_ME_RULE = { 69 | // words ending -ma which change to -me (not sure this is a category) 70 | "vittima" 71 | }; 72 | 73 | private static final String[] CATEGORY_IO_II_RULE = { 74 | // words ending -io where the i is stressed 75 | "zio", 76 | }; 77 | 78 | private static final String[] CATEGORY_CO_CI_RULE = { 79 | // words ending -co preceded by a vowel 80 | "amico", 81 | }; 82 | 83 | private static final String[] CATEGORY_GO_GI_RULE = { 84 | // words ending -go preceded by a vowel 85 | "asparago", 86 | }; 87 | 88 | private static final String[] CATEGORY_CIA_CIE_RULE = { 89 | // words ending -cia preceded by a vowel or where the i is stressed 90 | "farmacia", 91 | }; 92 | 93 | private static final String[] CATEGORY_GIA_GIE_RULE = { 94 | // words ending -gia preceded by a vowel or where the i is stressed 95 | "valigia", 96 | }; 97 | 98 | private final List rules = Arrays.asList(new Rule[] { 99 | 100 | // Blank word 101 | new RegexReplacementRule("^(\\s)$", "$1"), 102 | 103 | // Irregular nouns 104 | new IrregularMappingRule(IRREGULAR_NOUNS, "(?i)" + disjunction(IRREGULAR_NOUNS.keySet()) + "$"), 105 | 106 | // Nouns ending in -ista (referring to people) 107 | new SuffixInflectionRule("-ista", "-isti"), // assume male form 108 | 109 | // Irregular nouns that do not inflect in the plural 110 | new CategoryInflectionRule(CATEGORY_UNINFLECTED_NOUNS, "-", "-"), 111 | new SuffixInflectionRule("-[\u00e0|\u00e8|\u00ec|\u00f9]", "-", "-"), 112 | new SuffixInflectionRule("-ie?", "-", "-"), 113 | 114 | // Irregular masculine nouns ending in -ma 115 | new CategoryInflectionRule(CATEGORY_MA_MA_RULE, "-ma", "-ma"), 116 | new CategoryInflectionRule(CATEGORY_MA_ME_RULE, "-ma", "-me"), 117 | new SuffixInflectionRule("-ma", "-mi"), 118 | 119 | // Regular nouns ending in -o 120 | 121 | new CategoryInflectionRule(CATEGORY_IO_II_RULE, "-io", "-ii"), 122 | new SuffixInflectionRule("-io", "-o", "-"), 123 | 124 | new CategoryInflectionRule(CATEGORY_CO_CI_RULE, "-co", "-ci"), 125 | new SuffixInflectionRule("-co", "-chi"), 126 | 127 | new CategoryInflectionRule(CATEGORY_GO_GI_RULE, "-go", "-gi"), 128 | new SuffixInflectionRule("-go", "-ghi"), 129 | 130 | new SuffixInflectionRule("-o", "-i"), 131 | 132 | // Regular nouns ending in -a 133 | 134 | new SuffixInflectionRule("-ca", "-che"), 135 | 136 | new SuffixInflectionRule("-ga", "-ghe"), 137 | 138 | new CategoryInflectionRule(CATEGORY_CIA_CIE_RULE, "-cia", "-cie"), 139 | new SuffixInflectionRule("-cia", "-ce"), 140 | 141 | new CategoryInflectionRule(CATEGORY_GIA_GIE_RULE, "-gia", "-gie"), 142 | new SuffixInflectionRule("-gia", "-ge"), 143 | 144 | new SuffixInflectionRule("-a", "-e"), 145 | 146 | // Regular nouns ending in -e 147 | 148 | new SuffixInflectionRule("-e", "-i"), 149 | 150 | // Don't inflect by default 151 | new SuffixInflectionRule("-", "-"), 152 | }); 153 | 154 | /** 155 | * Default constructor. 156 | */ 157 | public NounPluralizer() { 158 | setRules(rules); 159 | setLocale(Locale.ITALIAN); 160 | } 161 | 162 | 163 | } 164 | -------------------------------------------------------------------------------- /inflector/src/main/java/org/jvnet/inflector/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | Classes for inflecting natural language words, especially for forming plurals. 4 |

5 | -------------------------------------------------------------------------------- /inflector/src/main/java/org/jvnet/inflector/rule/AbstractRegexReplacementRule.java: -------------------------------------------------------------------------------- 1 | package org.jvnet.inflector.rule; 2 | 3 | import java.io.Serializable; 4 | import java.util.Set; 5 | import java.util.regex.Matcher; 6 | import java.util.regex.Pattern; 7 | 8 | import org.jvnet.inflector.Rule; 9 | 10 | /** 11 | *

12 | * An abstract rule specified using a regular expression and replacement. Subclasses 13 | * must implement {@link #replace} to perform the actual replacement. 14 | *

15 | * @author Tom White 16 | */ 17 | public abstract class AbstractRegexReplacementRule implements Rule, Serializable { 18 | 19 | /** */ 20 | private static final long serialVersionUID = -3287025981231837237L; 21 | private final Pattern pattern; 22 | 23 | /** 24 | *

25 | * Construct a rule using the given regular expression. 26 | *

27 | * @param regex the regular expression used to match words. Match information 28 | * is available to subclasses in the {@link #replace} method. 29 | */ 30 | public AbstractRegexReplacementRule(String regex) { 31 | this.pattern = Pattern.compile(regex); 32 | } 33 | 34 | public boolean applies(String word) { 35 | return pattern.matcher(word).matches(); 36 | } 37 | 38 | public String apply(String word) { 39 | Matcher matcher = pattern.matcher(word); 40 | if (!matcher.matches()) { 41 | throw new IllegalArgumentException("Word '" + word + "' does not match regex: " + pattern.pattern()); 42 | } 43 | return replace(matcher); 44 | } 45 | 46 | /** 47 | *

48 | * Use the state in the given {@link Matcher} to perform a replacement. 49 | *

50 | * @param matcher the matcher used to match the word 51 | * @return the transformed word 52 | */ 53 | public abstract String replace(Matcher matcher); 54 | 55 | /** 56 | *

57 | * Form the disjunction of the given regular expression patterns. 58 | * For example if patterns contains "a" and "b" then the disjunction is "(a|b)", 59 | * that is, "a or b". 60 | *

61 | * @param patterns an array of regular expression patterns 62 | * @return a pattern that matches if any of the input patterns match 63 | */ 64 | public static String disjunction(String[] patterns) { 65 | String regex = ""; 66 | for (int i = 0; i < patterns.length; i++) { 67 | regex += patterns[i]; 68 | if (i < patterns.length - 1) { 69 | regex += "|"; 70 | } 71 | } 72 | return "(?:" + regex + ")"; 73 | } 74 | 75 | /** 76 | *

77 | * Form the disjunction of the given regular expression patterns. 78 | * For example if patterns contains "a" and "b" then the disjunction is "(a|b)", 79 | * that is, "a or b". 80 | *

81 | * @param patterns a set of regular expression patterns 82 | * @return a pattern that matches if any of the input patterns match 83 | */ 84 | public static String disjunction(Set patterns) { 85 | return disjunction(patterns.toArray(new String[0])); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /inflector/src/main/java/org/jvnet/inflector/rule/CategoryInflectionRule.java: -------------------------------------------------------------------------------- 1 | package org.jvnet.inflector.rule; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | *

7 | * A rule for specifying an inflection using suffixes that only applies to a 8 | * subset of words with those suffixes (a category). 9 | *

10 | * @author Tom White 11 | */ 12 | public class CategoryInflectionRule extends SuffixInflectionRule implements Serializable { 13 | 14 | /** */ 15 | private static final long serialVersionUID = 8202369008967739022L; 16 | private final String regex; 17 | 18 | /** 19 | *

20 | * Construct a rule for words with suffix singularSuffix which 21 | * becomes pluralSuffix in the plural. 22 | *

23 | * @param words the set of words that define this category 24 | * @param singularSuffix the singular suffix, starting with a "-" character 25 | * @param pluralSuffix the plural suffix, starting with a "-" character 26 | */ 27 | public CategoryInflectionRule(String[] words, String singularSuffix, String pluralSuffix) { 28 | super(singularSuffix, pluralSuffix); 29 | this.regex = "(?i)" + AbstractRegexReplacementRule.disjunction(words); 30 | } 31 | 32 | @Override 33 | public boolean applies(String word) { 34 | return word.matches(regex); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /inflector/src/main/java/org/jvnet/inflector/rule/IrregularMappingRule.java: -------------------------------------------------------------------------------- 1 | package org.jvnet.inflector.rule; 2 | import java.io.Serializable; 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.regex.Matcher; 6 | 7 | /** 8 | *

9 | * A rule for specifying an irregular inflection using a combination of a map of 10 | * singular to plural forms and a regular expression replacement. Subclasses 11 | * cn implement {@link #replace} to perform the actual replacement, which by default 12 | * uses the map to substitute a plural form for the corresponding singular form found in group 0 13 | * of the regular expression match. 14 | *

15 | * @author Tom White 16 | */ 17 | public class IrregularMappingRule extends AbstractRegexReplacementRule implements Serializable{ 18 | 19 | /** */ 20 | private static final long serialVersionUID = 9069582525363046599L; 21 | protected final Map mappings; 22 | 23 | /** 24 | *

25 | * Construct a rule using the given regular expression and irregular forms map. 26 | *

27 | * @param wordMappings the map of singular to plural forms 28 | * @param regex the regular expression used to match words. Match information 29 | * is available to subclasses in the {@link #replace} method. 30 | */ 31 | public IrregularMappingRule(Map wordMappings, String regex) { 32 | super(regex); 33 | this.mappings = wordMappings; 34 | } 35 | 36 | @Override 37 | public String replace(Matcher m) { 38 | return mappings.get(m.group(0).toLowerCase()); 39 | } 40 | 41 | /** 42 | *

43 | * Turn the array of String array mapping pairs into a map. 44 | *

45 | * @param wordMappings 46 | * @return a map of singular to plural forms 47 | */ 48 | public static Map toMap(String[][] wordMappings) { 49 | Map mappings = new HashMap(); 50 | for (int i = 0; i < wordMappings.length; i++) { 51 | String singular = wordMappings[i][0]; 52 | String plural = wordMappings[i][1]; 53 | mappings.put(singular, plural); 54 | } 55 | return mappings; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /inflector/src/main/java/org/jvnet/inflector/rule/RegexReplacementRule.java: -------------------------------------------------------------------------------- 1 | package org.jvnet.inflector.rule; 2 | import java.io.Serializable; 3 | import java.util.regex.Matcher; 4 | 5 | /** 6 | *

7 | * A rule specified using a regular expression and a replacement string. 8 | *

9 | * @author Tom White 10 | */ 11 | public class RegexReplacementRule extends AbstractRegexReplacementRule implements Serializable { 12 | 13 | /** */ 14 | private static final long serialVersionUID = -2153299891328152681L; 15 | private final String replacement; 16 | 17 | /** 18 | * Construct a rule using the given regular expression and replacement string. 19 | * @param regex the regular expression used to match words 20 | * @param replacement the string to use during replacement. 21 | * The replacement string may contain references to subsequences captured matching. 22 | * See {@link Matcher#appendReplacement}. 23 | */ 24 | public RegexReplacementRule(String regex, String replacement) { 25 | super(regex); 26 | this.replacement = replacement; 27 | } 28 | 29 | @Override 30 | public String replace(Matcher matcher) { 31 | return matcher.replaceFirst(replacement); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /inflector/src/main/java/org/jvnet/inflector/rule/SuffixInflectionRule.java: -------------------------------------------------------------------------------- 1 | package org.jvnet.inflector.rule; 2 | import java.io.Serializable; 3 | 4 | import org.jvnet.inflector.Rule; 5 | 6 | /** 7 | *

8 | * A rule for specifying an inflection using suffixes. For example, the English nouns 9 | * which have the suffix -y, generally change the suffix to -ies in the plural. Such a rule would 10 | * be expressed as new SuffixInflectionRule("-y", "-ies"). 11 | *

12 | * @author Tom White 13 | */ 14 | public class SuffixInflectionRule implements Rule, Serializable{ 15 | 16 | /** */ 17 | private static final long serialVersionUID = -6412698059095031731L; 18 | private final String regex; 19 | private final String singularSuffix; 20 | private final String pluralSuffix; 21 | 22 | /** 23 | *

24 | * Construct a rule for words with suffix singularSuffix which 25 | * becomes pluralSuffix in the plural. 26 | *

27 | * @param singularSuffix the singular suffix, starting with a "-" character 28 | * @param pluralSuffix the plural suffix, starting with a "-" character 29 | */ 30 | public SuffixInflectionRule(String singularSuffix, String pluralSuffix) { 31 | this(singularSuffix, singularSuffix, pluralSuffix); 32 | } 33 | 34 | /** 35 | *

36 | * Construct a rule for words with suffix suffix, where 37 | * singularSuffix 38 | * becomes pluralSuffix in the plural. 39 | * @param suffix the suffix, starting with a "-" character, which the end of the word must match. 40 | * Note that regular expression patterns may be used. 41 | * @param singularSuffix the singular suffix, starting with a "-" character. 42 | * Note that it must be true that suffix ends with singularSuffix. 43 | * @param pluralSuffix the plural suffix, starting with a "-" character 44 | *

45 | */ 46 | public SuffixInflectionRule(String suffix, String singularSuffix, String pluralSuffix) { 47 | // TODO: check suffix ends with singularSuffix? 48 | this.regex = "(?i).*" + suffix.substring(1) + "$"; 49 | this.singularSuffix = singularSuffix; 50 | this.pluralSuffix = pluralSuffix; 51 | } 52 | 53 | public boolean applies(String word) { 54 | return word.matches(regex); 55 | } 56 | 57 | public String apply(String word) { 58 | int i = word.toUpperCase().lastIndexOf(singularSuffix.substring(1).toUpperCase()); 59 | //TODO: check i 60 | // TODO: make case insensitive 61 | return word.substring(0, i) + pluralSuffix.substring(1); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /inflector/src/main/java/org/jvnet/inflector/rule/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | Classes for specifying inflections using rules. 4 |

5 | -------------------------------------------------------------------------------- /inflector/src/main/java/overview.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Inflector - User Guide 4 | 5 | 6 | 7 | 8 | 9 |

10 | Inflector provides an API for forming the plurals of nouns. Here's a simple example: 11 |

12 | 13 |
System.out.println(Noun.pluralOf("loaf"));
14 | 15 |

16 | This will print 17 |

18 | 19 |
loaves
20 | 21 |

22 | to the console. 23 |

24 | 25 |

26 | It's handy to use Java 5 static imports to make this more readable, 27 | particularly if you are forming lots of plurals. 28 |

29 | 30 |
import static org.jvnet.inflector.Noun.pluralOf;
 31 | ...
 32 | System.out.println(pluralOf("loaf"));
 33 | 
34 | 35 |

Nouns

36 | 37 |

38 | It is often useful to use a {@link java.util.Formatter}. For example, 39 |

40 | 41 |
System.out.printf("I bought 10 %s.", pluralOf("loaf"));
 42 | 
43 | 44 |

45 | prints 46 |

47 | 48 |
I bought 10 loaves.
49 | 50 |

51 | Of course, you can parameterize the number, as follows. 52 |

53 | 54 |
int n = 10;
 55 | System.out.printf("I bought %d %s.", n, pluralOf("loaf", n));
 56 | 
57 | 58 |

59 | Notice that you pass the number into the pluralOf method to make sure the noun agrees. 60 | For example, if n = 1 in the previous example, it would correctly print 61 |

62 | 63 |
I bought 1 loaf.
64 | 65 |

Internationalization

66 | 67 |

68 | The examples so far use the default locale to determine the pluralization algorithm to use. You can explictly set 69 | the locale to use by passing another argument: 70 |

71 | 72 |
System.out.println(pluralOf("pagnotta", Locale.ITALIAN));
 73 | 
74 | 75 |

76 | prints 77 |

78 | 79 |
pagnotte
80 | 81 |

Custom Pluralization

82 | 83 |

84 | The pluralization algorithms that come with Inflector may not meet your needs. Perhaps there is no algorithm for your language, 85 | or perhaps the rules don't fit the usage that is appropriate for your application. The English 86 | pluralizer, for example, is fairly modern: it does not support many classical rules that are rare nowadays. 87 |

88 | 89 |

90 | In this case it is straightforward to write your own pluralizer, or simply extend another one to override some of its rules. 91 | The follow code overrides the plural for box to boxen by using a {@link org.jvnet.inflector.rule.RegexReplacementRule}: 92 |

93 | 94 |
List<Rule> customRules = new ArrayList<Rule>();
 95 | customRules.add(new RegexReplacementRule("(?i)(.*)box", "$1boxen"));
 96 | Pluralizer customPluralizer = new RuleBasedPluralizer(customRules, Locale.ENGLISH, Noun.pluralizer(Locale.ENGLISH));
 97 | System.out.println(pluralOf("box"));
 98 | System.out.println(pluralOf("box", customPluralizer));
 99 | System.out.println(pluralOf("chatterbox", customPluralizer));
100 | 
101 | 102 |

103 | This prints 104 |

105 | 106 |
boxes
107 | boxen
108 | chatterboxen
109 | 110 |

111 | If you are interested in writing more complex rules, there are many other implementations of 112 | {@link org.jvnet.inflector.Rule} in the {@link org.jvnet.inflector.rule} package. 113 |

114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 4.0.0 5 | 6 | com.github.wwadge 7 | hbnpojogen 8 | 1.5.13 9 | pom 10 | 11 | Hibernate POJO Generator 12 | The parent project of Hibernate POJO Generator artifacts. 13 | 14 | https://github.com/wwadge/hbnpojogen 15 | 16 | 17 | 18 | The Apache License, Version 2.0 19 | http://www.apache.org/licenses/LICENSE-2.0.txt 20 | 21 | 22 | 23 | 24 | 25 | Wallace Wadge 26 | wwadge@gmail.com 27 | Wallace Wadge 28 | https://github.com/wwadge/hbnpojogen 29 | 30 | 31 | 32 | 33 | scm:git:git://github.com/wwadge/hbnpojogen.git 34 | scm:git:ssh://github.com:wwadge/hbnpojogen.git 35 | https://github.com/wwadge/hbnpojogen 36 | 37 | 38 | 39 | hbnpojogen-core 40 | hbnpojogen-persistence 41 | hbnpojogen-maven 42 | 43 | 44 | 45 | 3.5.2-Final 46 | 2.5.6 47 | true 48 | 49 | 50 | 51 | 52 | 53 | com.github.wwadge 54 | hbnpojogen-core 55 | ${project.version} 56 | 57 | 58 | 59 | com.google.guava 60 | guava 61 | 18.0 62 | 63 | 64 | 65 | commons-configuration 66 | commons-configuration 67 | 1.5 68 | 69 | 70 | commons-io 71 | commons-io 72 | 1.4 73 | 74 | 75 | 76 | commons-lang 77 | commons-lang 78 | 2.4 79 | 80 | 81 | 82 | commons-collections 83 | commons-collections 84 | 3.2.1 85 | 86 | 87 | 88 | org.hibernate 89 | hibernate-core 90 | ${hibernate.version} 91 | 92 | 93 | 94 | org.hibernate 95 | hibernate-validator 96 | 4.1.0.Final 97 | 98 | 99 | 100 | net.java.dev.inflector 101 | inflector 102 | 0.7.0 103 | 104 | 105 | 106 | mysql 107 | mysql-connector-java 108 | 8.0.17 109 | 110 | 111 | 112 | org.postgresql 113 | postgresql 114 | 42.2.5 115 | runtime 116 | true 117 | 118 | 119 | 120 | org.apache.velocity 121 | velocity 122 | 1.5 123 | 124 | 125 | 126 | net.sourceforge.jtds 127 | jtds 128 | 1.2.4 129 | runtime 130 | 131 | 132 | 133 | org.springframework 134 | spring-beans 135 | ${spring.version} 136 | 137 | 138 | 139 | org.springframework 140 | spring-context 141 | ${spring.version} 142 | 143 | 144 | 145 | log4j 146 | log4j 147 | 1.2.16 148 | compile 149 | 150 | 151 | 152 | org.apache.maven 153 | maven-plugin-api 154 | 3.3.3 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | maven-source-plugin 163 | 2.1.2 164 | 165 | 166 | package 167 | 168 | jar 169 | 170 | 171 | 172 | 173 | 174 | 175 | org.apache.maven.plugins 176 | maven-plugin-plugin 177 | 3.4 178 | 179 | 180 | 181 | maven-compiler-plugin 182 | 2.0.1 183 | 184 | 1.8 185 | 1.8 186 | 187 | 188 | 189 | org.sonatype.plugins 190 | nexus-staging-maven-plugin 191 | 1.6.7 192 | true 193 | 194 | ossrh 195 | https://oss.sonatype.org/ 196 | true 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | ossrh 209 | https://oss.sonatype.org/content/repositories/snapshots 210 | 211 | 212 | 213 | 214 | --------------------------------------------------------------------------------