📄 eogjavasource.eotemplate
字号:
<$comment
EO Template for use by "eogenerator" based upon MiscMerge engine.
You may customize this file to modify the templates generated
by this tool. See the MiscMerge documentation for a description
of the parsing language. The engine gets passed this file and an
EOEntity to process, so the methods used must be ones that an
EOEntity can respond to.
BE SURE NOT TO INCLUDE DATES IN THIS FILE. Since the "eogenerator"
tool tries to compare the newly generated file with the old file,
adding dates to this file will guarantee the old file gets
overridden by the new file, forcing a recompilation of your EO.$>
// <$GEN_PREFIX$><$classNameWithoutPackage$>.java
//
// Created by eogenerator
// DO NOT EDIT. Make changes to <$classNameWithoutPackage$>.java instead.
<$foreach package classPackage do$>package <$package$>;
<$endforeach do$>
import com.webobjects.foundation.*;
import com.webobjects.eocontrol.*;
import java.math.BigDecimal;
import java.util.Enumeration;
<$comment This is how to put in a custom EO superclass. We also declare
this class as being abstract, since it should never be instantiated.
$>
public abstract class <$GEN_PREFIX$><$classNameWithoutPackage$> extends <$if hasParentEntity$><$javaParentClassName$><$else$>MyEOSuperclass<$endif$>
{
<$comment
Some people like to have constant strings defined for each key. For an
attribute named fooBar, this will declare a FOO_BAR_KEY constant string,
which can be used in calls to valueForKey(), addObjectToBothSides..., etc.
A constant of ENTITY_NAME can be used for fetch specs and other methods.
This lets the compiler flag usages of these keys when the names change.
Additionally, it can be handy to have constants defined for the name
of the database table, the names of all the attribute column names, and fetch
specifications.
$>
public static final String ENTITY_NAME = "<$name$>";
<$if externalName$>
public static final String ENTITY_TABLE_NAME = "<$externalName$>";<$endif$>
<$foreach attribute attributes.@sortedNameArray do$>
public static final String <$attribute.name.uppercaseUnderbarString$>_KEY = "<$attribute.name$>";<$endforeach$>
<$foreach attribute attributes.@sortedNameArray do$><$if attribute.columnName$>
public static final String <$attribute.name.uppercaseUnderbarString$>_COLKEY = "<$attribute.columnName$>";<$endif$><$endforeach$>
<$foreach rel classToOneRelationships.@sortedNameArray do$>
public static final String <$rel.name.uppercaseUnderbarString$>_KEY = "<$rel.name$>";<$endforeach$>
<$foreach rel classToManyRelationships.@sortedNameArray do$>
public static final String <$rel.name.uppercaseUnderbarString$>_KEY = "<$rel.name$>";<$endforeach$>
<$foreach spec javaBeautifiedFetchSpecificationDictionaries.@sortedNameArray do$>
public static final String <$spec.fetchName.uppercaseUnderbarString$>_SPEC = "<$spec.fetchName$>";<$endforeach$>
<$comment
These do the same thing, but use mixed case strings instead of all uppercase.
These are commented out by default
public static final String EntityName = "<$name$>";
<$if externalName$>
public static final String EntityTableName = "<$externalName$>";<$endif$>
<$foreach attribute attributes.@sortedNameArray do$>
public static final String <$attribute.name.initialCapitalString$>Key = "<$attribute.name$>";<$endforeach$>
<$foreach attribute attributes.@sortedNameArray do$><$if attribute.columnName$>
public static final String <$attribute.name.initialCapitalString$>ColKey = "<$attribute.columnName$>";<$endif$><$endforeach$>
<$foreach rel classToOneRelationships.@sortedNameArray do$>
public static final String <$rel.name.initialCapitalString$>Key = "<$rel.name$>";<$endforeach$>
<$foreach rel classToManyRelationships.@sortedNameArray do$>
public static final String <$rel.name.initialCapitalString$>Key = "<$rel.name$>";<$endforeach$>
<$foreach spec javaBeautifiedFetchSpecificationDictionaries.@sortedNameArray do$>
public static final String <$spec.fetchName.initialCapitalString$>Spec = "<$spec.fetchName$>";<$endforeach$>
$><$comment
This section will create a method to create a new instance of this entity.
It is essentially identical to EOUtilies' createAndInsertInstance method.
This won't necessarily work if you are using inheritance. The commented out
method following this one would be generally a better method to use if
you need to deal with inheritance.
$><$if !isAbstractEntity$>
public static <$classNameWithoutPackage$> newInstance(EOEditingContext context) {
EOClassDescription desc = EOClassDescription.classDescriptionForEntityName(ENTITY_NAME);
EOEnterpriseObject object = desc.createInstanceWithEditingContext(context, null);
context.insertObject(object);
return (<$classNameWithoutPackage$>)object;
}<$endif$>
<$comment Java does not allow static methods of the same name in a subclass
to return a different type, so for some types of inheritance the above will
not work. In these cases, declare the method like this:
public static <$classNameWithoutPackage$> new<$classNameWithoutPackage$>Instance(EOEditingContext context)
$>
public <$GEN_PREFIX$><$classNameWithoutPackage$>() {
super();
}
<$comment
Add methods to call named fetch specifications, with any qualifier bindings having typed
parameters.
$><$foreach FetchSpec javaBeautifiedFetchSpecificationDictionaries.@sortedNameArray do$>
public static NSArray objectsFor<$FetchSpec.niceName$>(EOEditingContext context<$foreach Binding FetchSpec.bindings do2$>, <$Binding.codeType$><$Binding.name$>Binding<$endforeach do2$>) {
EOFetchSpecification spec = EOFetchSpecification.fetchSpecificationNamed("<$FetchSpec.fetchName$>", "<$name$>");
<$if FetchSpec.bindings.@count > 0$>
NSMutableDictionary bindings = new NSMutableDictionary();
<$foreach Binding FetchSpec.bindings do2$>
if (<$Binding.name$>Binding != null)
bindings.setObjectForKey(<$Binding.name$>Binding, "<$Binding.name$>");<$endforeach do2$>
spec = spec.fetchSpecificationWithQualifierBindings(bindings);
<$endif$>
return context.objectsWithFetchSpecification(spec);
}
<$endforeach do$>
<$foreach Attribute classAttributes.@sortedNameArray do$>
public <$Attribute.javaValueClassName$> <$Attribute.name$>() {
return (<$Attribute.javaValueClassName$>)storedValueForKey("<$Attribute.name$>");
}
public void set<$Attribute.name.initialCapitalString$>(<$Attribute.javaValueClassName$> aValue) {
takeStoredValueForKey(aValue, "<$Attribute.name$>");
}<$comment
ADVANCED EXAMPLE
The following code shows an example of using the userInfo dictionary on an attribute to create
additional methods.
This example allows the user to define the key 'abbreviate' to create a method that will turn a
string into a abbreviated version. This can be really handy in WO components where you may need
to display a text string that could be very long, but need it to always fit in a certain area.
Additional methods could be made to make shorter or longer abbreviated strings. The code checks
to see if the type of the attribute is a String and if the abbreviated length is at least greater
than 3 characters, before it will create the method.
<$if Attribute.javaValueClassName eq 'String' and Attribute.userInfo.abbreviate gt 3$>
public String abbreviated<$Attribute.name.initialCapitalString$>() {
String value = <$Attribute.name$>();
if ( value != null && value.length() > <$Attribute.userInfo.abbreviate$> )
value = value.substring(0,<$Attribute.userInfo.abbreviate$> - 3) + "...";
return value;
}
<$endif$>
This is just one example of data manipulation that eogenerator can do. You could have methods that
uppercase values, strip blanks, encrypt the text, etc. all determined by entries in the userInfo
dictionary. See below for a To-Many relationship example.
$>
<$endforeach do$>
<$foreach ToOneRelationship classToOneRelationships.@sortedNameArray do$>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -