Methods Summary |
---|
protected static com.sun.jdo.api.persistence.model.Model | NewModel(java.lang.String testName, java.lang.String modelName)Create a new Model of the requested type. If the class definition
exists in the class path of the environment, then this method will
create a new instance of the Model.
String prefixes[] =
{"java.awt", "java.applet", "javax.swing", "javax.ejb"};// NOI18N
String classes[] = {"java.lang.Throwable"}; // NOI18N
String collectionClasses[] = { "java.util.Collection", // NOI18N
"java.util.AbstractCollection", // NOI18N
//"java.util.List", "java.util.AbstractList", // NOI18N
"java.util.Set", "java.util.AbstractSet", // NOI18N
//"java.util.ArrayList", "java.util.Vector", // NOI18N
"java.util.HashSet", // NOI18N
//"com.sun.jdo.spi.persistence.support.sqlstore.sco.ArrayList", // NOI18N
//"com.sun.jdo.spi.persistence.support.sqlstore.sco.Vector", // NOI18N
"com.sun.jdo.spi.persistence.support.sqlstore.sco.HashSet"}; // NOI18N
String mutableScoClasses[] = {"java.util.Date", // NOI18N
"com.sun.jdo.spi.persistence.support.sqlstore.sco.Date", "java.sql.Date",// NOI18N
"com.sun.jdo.spi.persistence.support.sqlstore.sco.SqlDate", // NOI18N
"java.sql.Time", "com.sun.jdo.spi.persistence.support.sqlstore.sco.SqlTime", // NOI18N
"java.sql.Timestamp", // NOI18N
"com.sun.jdo.spi.persistence.support.sqlstore.sco.SqlTimestamp"}; // NOI18N
String scoClasses[] = {"java.lang.String", // NOI18N
"java.lang.Character", "java.lang.Boolean", // NOI18N
"java.lang.Long", "java.lang.Number", "java.lang.Byte", // NOI18N
"java.lang.Short", "java.lang.Integer", "java.lang.Float", // NOI18N
"java.lang.Double", "java.math.BigDecimal", // NOI18N
"java.math.BigInteger"}; // NOI18N
_illegalPrefixes = Arrays.asList(prefixes);
_illegalClasses = Arrays.asList(classes);
_collectionClasses = Arrays.asList(collectionClasses);
_mutableScoClasses = new ArrayList(Arrays.asList(mutableScoClasses));
_mutableScoClasses.addAll(_collectionClasses);
_scoClasses = new ArrayList(Arrays.asList(scoClasses));
_scoClasses.addAll(_mutableScoClasses);
// always load the runtime model
RUNTIME = NewModel(null, "com.sun.jdo.api.persistence.model.RuntimeModel"); //NOI18N
// always load the enhancer model
ENHANCER = NewModel(null, "com.sun.jdo.api.persistence.model.EnhancerModel"); //NOI18N
Class DynamicClass = null;
Model model = null;
try {
if (testName != null)
// try this class as a precondition to the real class to load
Class.forName (testName);
DynamicClass = Class.forName (modelName);
if (DynamicClass != null)
model = (Model) DynamicClass.newInstance();
}
catch (Exception e) {
// this is expected in the environment
}
return model;
|
public boolean | addFieldElement(PersistenceClassElement element, java.lang.String fieldName)Adds a PersistenceFieldElement for the specified field to the
supplied PersistenceClassElement, creating a RelationshipElement if
necessary.
String fieldType = getFieldType(element.getName(), fieldName);
boolean isCollection = isCollection(fieldType);
try
{
// check if should be relationship here
if (isPersistent(fieldType) || isCollection)
{
RelationshipElement relationship = new RelationshipElement(
new RelationshipElementImpl(fieldName), element);
if (isCollection)
{
relationship.setCollectionClass(
getDefaultCollectionClass(fieldType));
}
else // set upper bound = 1 (jdo model should really do this)
relationship.setUpperBound(1);
element.addField(relationship);
}
else
{
element.addField(new PersistenceFieldElement(new
PersistenceFieldElementImpl(fieldName), element));
}
return true;
}
catch (ModelException e)
{} // will return false
return false;
|
public void | convertDefaultFields(java.lang.String className)Adds the default allowable persistent fields to the persistent class
with the specified name. This is the second phase of converting
a class to be persistence-capable.
convertFields(className, getFields(className));
|
public void | convertFields(java.lang.String className, java.util.List fields)Adds the allowable persistent fields from the supplied list
to the persistent class with the specified name.
PersistenceClassElement element = getPersistenceClass(className);
if (element != null)
{
Iterator iterator = fields.iterator();
// iterate the list of fields and create corresponding
// PersistenceFieldElements (& RelationshipElements)
while (iterator.hasNext())
{
String fieldName = (String)iterator.next();
if (isPersistentAllowed(className, fieldName) &&
shouldBePersistent(className, fieldName))
{
addFieldElement(element, fieldName);
}
}
/* comment out -- not supporting concurrency groups for beta
// add everything to one concurrency group by default
PersistenceFieldElement[] persistentFields = element.getFields();
if ((persistentFields != null) && (persistentFields.length > 0))
{
String defaultGroupName = I18NHelper.getMessage(getMessages(),
"jdo.concurrency_group.default");
ConcurrencyGroupElement group = new ConcurrencyGroupElement(
new ConcurrencyGroupElementImpl(defaultGroupName), element);
try
{
group.addFields(persistentFields);
element.addConcurrencyGroup(group);
}
catch (ModelException e)
{} // just don't add this group
}*/
}
|
public void | convertToPersistenceCapable(java.lang.String className, boolean flag)Converts the class with the supplied name to or from persistence
capable depending on the flag.
boolean classIsPersistent = isPersistent(className);
Exception conversionException = null;
if (flag && !classIsPersistent &&
isPersistenceCapableAllowed(className))
{
try
{
// this calls updateKeyForClass which updates
// the mapping cache and the set of classes known to be non PC
createSkeletonMappingClass(className);
}
catch (Exception e)
{
// need to unconvert whatever partial conversion succeeded
conversionException = e;
}
}
if ((!flag && classIsPersistent) || (conversionException != null))
{
try
{
// delete the mapping file
deleteFile(className, getFileNameWithExtension(className));
synchronized (this._classes)
{
// remove the corresponding MappingClassElement from cache
_classes.remove(className);
// put the class in the set of classes known to be non PC
_nonPCClasses.add(className);
}
}
catch (Exception e) // rethrow if not a problem during unconvert
{
if (conversionException == null)
conversionException = e;
}
}
if (conversionException != null) // rethrow the exception
{
if (conversionException instanceof RuntimeException)
throw (RuntimeException)conversionException;
else if (conversionException instanceof IOException)
throw (IOException)conversionException;
}
|
public void | convertToPersistenceCapable(java.lang.String className)Converts the class with the supplied name to persistence-capable,
then convert its default fields and save it to the xml file.
convertToPersistenceCapable(className, true);
convertDefaultFields(className);
storeMappingClass(className);
|
protected abstract java.io.BufferedOutputStream | createFile(java.lang.String className, java.lang.String baseFileName, java.lang.String extension)Creates a file with the given base file name and extension
parallel to the supplied class (if it does not yet exist).
|
private void | createSkeletonMappingClass(java.lang.String className)Creates a PersistenceClassElement with the specified name, then wraps
it in a mapping class and stores it in the hash map of classes.
This is the first phase of converting a class to be persistence-capable.
PersistenceClassElement element = new PersistenceClassElement(
new PersistenceClassElementImpl(className));
updateKeyForClass(new MappingClassElementImpl(element), null);
|
protected abstract void | deleteFile(java.lang.String className, java.lang.String fileName)Deletes the file with the given file name which is parallel
to the supplied class.
|
protected abstract java.lang.String | findPenultimateSuperclass(java.lang.String className)Returns the name of the second to top (top excluding java.lang.Object)
superclass for the given class name.
|
public java.util.List | getAllFields(java.lang.String className)Returns a list of names of all the field elements in the
class with the specified name. This list includes the inherited
fields.
List returnList = new ArrayList();
while (className != null)
{
returnList.addAll(getFields(className));
className = getSuperclass(className);
}
return returnList;
|
public java.lang.Object | getClass(java.lang.String className)Returns the class element with the specified className.
return getClass(className, null);
|
public abstract java.lang.Object | getClass(java.lang.String className, java.lang.ClassLoader classLoader)Returns the class element with the specified className.
|
public java.util.Map | getClassLoaderCache()Returns an unmodifiable copy of the ClassLoader cache.
This implementation returns null, but subclasses (such as RuntimeModel)
can override this method if they support a class loader cache.
return null;
|
public abstract java.lang.Object | getConstructor(java.lang.String className, java.lang.String[] argTypeNames)Returns the constructor element for the specified argument types
in the class with the specified name. Types are specified as type
names for primitive type such as int, float or as fully qualified
class names.
|
public abstract java.lang.String | getDeclaringClass(java.lang.Object memberElement)Returns the string representation of declaring class of
the specified member element. Note, the member element is
either a class element as returned by getClass, a field element
as returned by getField, a constructor element as returned by
getConstructor, or a method element as returned by getMethod
executed on the same model instance.
|
public java.lang.String | getDefaultCollectionClass(java.lang.String className)Returns the default collection class for the specified class. If
the specified class is an unspecified Collection type, the return
will be HashSet.
String collectionClass = "java.util.HashSet"; // NOI18N
// for dogwood, only support sets
/* if (className.indexOf("List") != -1) // NOI18N
collectionClass = "java.util.ArrayList"; // NOI18N
else if ("java.util.Vector".equals(className)) // NOI18N
collectionClass = className;
*/
return collectionClass;
|
public abstract java.lang.Object | getField(java.lang.String className, java.lang.String fieldName)Returns the field element for the specified fieldName in the class
with the specified className.
|
public java.lang.String | getFieldType(java.lang.String className, java.lang.String fieldName)Returns the field type for the specified fieldName in the class
with the specified className.
return getType(getField(className, fieldName));
|
public abstract java.util.List | getFields(java.lang.String className)Returns a list of names of all the declared field elements in the
class with the specified name.
|
protected java.lang.String | getFileName(java.lang.String className)Computes the base file name (without extension) for the supplied
class name by converting the package name to a path name.
return ((className != null) ?
className.replace('.", File.separatorChar) : null);
|
protected java.lang.String | getFileNameWithExtension(java.lang.String className)Computes the mapping file name (with extension) for the supplied
class name by converting the package name to a path name.
return getFileName(className) + "." + // NOI18N
MappingClassElement.MAPPING_EXTENSION;
|
public java.lang.Object | getInheritedField(java.lang.String className, java.lang.String fieldName)Returns the inherited field element for the specified fieldName in
the class with the specified className. Note that the class
with the specified className is not checked for this field, only
superclasses are checked.
String superClass = getSuperclass(className);
Object field = null;
while ((superClass != null) &&
((field = getField(superClass, fieldName)) == null))
{
superClass = getSuperclass(superClass);
}
return field;
|
public java.lang.Object | getInheritedMethod(java.lang.String className, java.lang.String methodName, java.lang.String[] argTypeNames)Returns the inherited method element for the specified method
name and argument types in the class with the specified name.
Types are specified as type names for primitive type such as
int, float or as fully qualified class names. Note that the class
with the specified className is not checked for this method, only
superclasses are checked.
String superClass = getSuperclass(className);
Object method = null;
while ((superClass != null) && ((method =
getMethod(superClass, methodName, argTypeNames)) == null))
{
superClass = getSuperclass(superClass);
}
return method;
|
protected abstract java.io.BufferedInputStream | getInputStreamForResource(java.lang.String className, java.lang.ClassLoader classLoader, java.lang.String resourceName)Returns the input stream with the supplied resource name found with
the supplied class name.
|
public java.util.Map | getMappingCache()Returns an unmodifiable copy of the MappingClassElement cache.
return Collections.unmodifiableMap(_classes);
|
public com.sun.jdo.api.persistence.model.mapping.MappingClassElement | getMappingClass(java.lang.String className)Returns the MappingClassElement created for the specified class name.
This method looks up the class in the internal cache. If not present
it loads the corresponding xml file containing the mapping information.
return getMappingClass(className, null);
|
public com.sun.jdo.api.persistence.model.mapping.MappingClassElement | getMappingClass(java.lang.String className, java.lang.ClassLoader classLoader)Returns the MappingClassElement created for the specified class name.
This method looks up the class in the internal cache. If not present
it loads the corresponding xml file containing the mapping information.
// This method synchronizes the access of the _classes cache,
// rather than using a synchronized map. This is for optimization only.
// Otherwise two parallel calls would read the mapping file twice,
// create two MCE instances and the second MCE instance would replace
// the first in the cache.
// Any other access of _classes potentially needs to be synchronized
// using the same variable _classes (e.g. updateKeyForClass).
synchronized (this._classes)
{
MappingClassElement mappingClass =
(MappingClassElement)_classes.get(className);
if (mappingClass == null)
{
// check whether the class is known to be non PC
if (_nonPCClasses.contains(className))
return null;
try
{
InputStream stream = getInputStreamForResource(className,
classLoader, getResourceNameWithExtension(className));
if (stream != null)
{
// if the file is empty, the archiver prints an
// exception, so protect against that case and
// return null without updating either cache
if (stream.available() > 0)
{
XMLInputStream xmlInput = new XMLInputStream(stream,
getClass().getClassLoader());
mappingClass =
(MappingClassElement)xmlInput.readObject();
xmlInput.close();
// postUnarchive performs version number checking
// and possible format conversions
mappingClass.postUnarchive();
// can't call updateKeyForClass here there are cases
// when the mapping class name doesn't match the
// classname (such as copy/paste, move etc.)
_classes.put(className, mappingClass);
// update the modified flags for the mapping and
// persistence classes since the xml archiver uses
// all the set methods
mappingClass.setModified(false);
getPersistenceClass(mappingClass).
setModified(false);
}
}
else
{
// stream is null, mapping file does not exist =>
// class is not PC, so store the class name in the
// set of classes known to be non PC
_nonPCClasses.add(className);
}
}
catch (ModelException e)
{
// MBO: print reason to logger
LogHelperModel.getLogger().log(Logger.WARNING,
e.getMessage());
return null;
}
catch (Exception e)
{
// MBO: print reason to logger
LogHelperModel.getLogger().log(Logger.WARNING,
I18NHelper.getMessage(getMessages(),
"file.cannot_read", className, e.toString())); //NOI18N
} // will return null
}
return mappingClass;
}
|
protected static final java.util.ResourceBundle | getMessages()
return _messages;
|
public abstract java.lang.Object | getMethod(java.lang.String className, java.lang.String methodName, java.lang.String[] argTypeNames)Returns the method element for the specified method name and argument
types in the class with the specified name. Types are specified as
type names for primitive type such as int, float or as fully qualified
class names.
|
public abstract int | getModifiers(java.lang.Object memberElement)Returns the modifier mask for the specified member element.
Note, the member element is either a class element as returned by
getClass, a field element as returned by getField, a constructor element
as returned by getConstructor, or a method element as returned by
getMethod executed on the same model instance.
|
protected int | getModifiers(java.lang.String className, java.lang.String fieldName)Returns the modifier mask for the specified fieldName in the class
with the specified className.
return getModifiers(getField(className, fieldName));
|
public int | getModifiersForClass(java.lang.String className)Returns the modifier mask for the specified className.
return getModifiers(getClass(className));
|
protected PersistenceClassElement | getPersistenceClass(com.sun.jdo.api.persistence.model.mapping.MappingClassElement mappingClass)Returns a PersistenceClassElement created from the mapping class.
return ((mappingClass == null) ? null :
((MappingClassElementImpl)mappingClass).getPersistenceElement());
|
public PersistenceClassElement | getPersistenceClass(java.lang.String className)Returns a PersistenceClassElement created from the specified class name.
Since our implementation of the mapping model class includes the
persistence class, this method finds the persistence class by extracting
it from the mapping class for the supplied name.
return getPersistenceClass(className, null);
|
public PersistenceClassElement | getPersistenceClass(java.lang.String className, java.lang.ClassLoader classLoader)Returns a PersistenceClassElement created from the specified class name.
Since our implementation of the mapping model class includes the
persistence class, this method finds the persistence class by extracting
it from the mapping class for the supplied name.
return getPersistenceClass(getMappingClass(className, classLoader));
|
public PersistenceFieldElement | getPersistenceField(java.lang.String className, java.lang.String fieldName)Returns the PersistenceFieldElement with the supplied fieldName found
in the supplied className.
return (hasField(className, fieldName) ?
getPersistenceFieldInternal(className, fieldName) : null);
|
protected PersistenceFieldElement | getPersistenceFieldInternal(java.lang.String className, java.lang.String fieldName)Returns the PersistenceFieldElement with the supplied fieldName found
in the supplied className.
PersistenceClassElement classElement = getPersistenceClass(className);
return ((classElement != null) ?
classElement.getField(fieldName) : null);
|
public java.lang.String | getRelatedClass(RelationshipElement element)Gets the name of the related class for a relationship element.
This method is added so that there is a common way to do this. It
checks if the argument is a collection relationship element (in which
case the element class should be returned) or not (in which case the
type should be returned). This should really be handled by the jdo
model directly, but it doesn't have access to the Model which is
necessary for finding the field type and whether it is a collection or
not.
if (element != null)
{
String fieldType = getFieldType(
element.getDeclaringClass().getName(), element.getName());
String relatedClass = (isCollection(fieldType) ?
element.getElementClass() : fieldType);
return (StringHelper.isEmpty(relatedClass) ? null :
relatedClass.trim());
}
return null;
|
protected java.lang.String | getResourceName(java.lang.String className)Computes the base resource name (without extension) for the supplied
class name by converting the package name to a resource name.
return ((className != null) ?
className.replace('.", '/") : null);
|
protected java.lang.String | getResourceNameWithExtension(java.lang.String className)Computes the mapping file resource name (with extension) for the
supplied class name by converting the package name to a resource name.
return getResourceName(className) + "." + // NOI18N
MappingClassElement.MAPPING_EXTENSION;
|
protected abstract java.lang.String | getSuperclass(java.lang.String className)Returns the name of the superclass for the given class name.
|
public java.util.ArrayList | getSupportedCollectionClasses(java.lang.String className)Computes the list of names of the possible collection classes for the
specified class.
String supportedSet = "java.util.HashSet"; // NOI18N
// String supportedList = "java.util.ArrayList"; // NOI18N
// String supportedVector = "java.util.Vector"; // NOI18N
ArrayList returnList = new ArrayList();
// for dogwood, only support sets
returnList.add(supportedSet);
/* if (className.indexOf("Collection") != -1) // NOI18N
{
returnList.add(supportedSet);
returnList.add(supportedList);
returnList.add(supportedVector);
}
else if (className.indexOf("List") != -1) // NOI18N
returnList.add(supportedList);
else if (className.indexOf("Set") != -1) // NOI18N
returnList.add(supportedSet);
else if (supportedVector.equals(className))
returnList.add(supportedVector);
*/
return returnList;
|
public abstract java.lang.String | getType(java.lang.Object element)Returns the string representation of type of the specified element.
If element denotes a field, it returns the type of the field.
If element denotes a method, it returns the return type of the method.
Note, element is either a field element as returned by getField, or a
method element as returned by getMethod executed on the same model
instance.
|
public boolean | hasClass(java.lang.String className)Determines if a class with the specified className exists.
return hasClass(className, null);
|
public boolean | hasClass(java.lang.String className, java.lang.ClassLoader classLoader)Determines if a class with the specified className exists.
return (getClass(className, classLoader) != null);
|
public abstract boolean | hasConstructor(java.lang.String className)Determines if the class with the specified name declares a constructor.
|
public boolean | hasField(java.lang.String className, java.lang.String fieldName)Determines if a field with the specified fieldName exists in the class
with the specified className.
return (getField(className, fieldName) != null);
|
public boolean | hasPersistentSuperclass(java.lang.String className)Determines if the specified className has a persistent superclass.
while ((className = getSuperclass(className)) != null)
{
if (isPersistent(className))
return true;
}
return false;
|
public abstract boolean | implementsInterface(java.lang.Object classElement, java.lang.String interfaceName)Determines if the specified class implements the specified interface.
Note, class element is a model specific class representation as returned
by a getClass call executed on the same model instance.
|
public abstract boolean | isArray(java.lang.String className, java.lang.String fieldName)Determines if a field with the specified fieldName in the class
with the specified className is an array.
|
public boolean | isByteArray(java.lang.String className, java.lang.String fieldName)Determines if a field with the specified fieldName in the class
with the specified className is a byte array.
return isByteArray(getFieldType(className, fieldName));
|
protected boolean | isByteArray(java.lang.String className)Determines if the specified className represents a byte array.
return ("byte[]".equals(className)); // NOI18N
|
public boolean | isCollection(java.lang.String className)Determines if the class name represents a collection.
return _collectionClasses.contains(className);
|
public boolean | isDefaultFetchGroup(java.lang.String className, java.lang.String fieldName)Determines if the specified className and fieldName pair represent a
field which is part of the default fetch group.
MappingClassElement mappingClass = getMappingClass(className);
try
{
return (MappingFieldElement.GROUP_DEFAULT ==
mappingClass.getField(fieldName).getFetchGroup());
}
catch (Exception e)
{} // will return false
return false;
|
public abstract boolean | isInterface(java.lang.String className)Determines if the specified className represents an interface type.
|
public boolean | isKey(java.lang.String className, java.lang.String fieldName)Determines if the specified className and fieldName pair represent a
key field.
if (hasField(className, fieldName))
{
PersistenceClassElement classElement =
getPersistenceClass(className);
if (classElement != null)
{
String keyClass = classElement.getKeyClass();
if (keyClass != null)
return hasField(keyClass, fieldName);
}
}
return false;
|
public boolean | isMutableSecondClassObject(java.lang.String className)Determines if the specified className represents a mutable second class
object. For this release, the class name is checked against a list of
supported mutable second class objects since user-defined second class
objects are not supported.
return _mutableScoClasses.contains(className);
|
public boolean | isPersistenceCapableAllowed(java.lang.String className)Determines if the specified className represents a legal candidate for
becoming a persistence capable class. A class may not become
persistence capable if it is declared as static or abstract, an
interface, a subclass of another persistence capable class
(either direct or indirect), an exception subclass, or a subclass
of ejb, swing, awt, or applet classes.
int modifier = getModifiersForClass(className);
if (!Modifier.isStatic(modifier) && !Modifier.isAbstract(modifier) &&
!isInterface(className) && !hasPersistentSuperclass(className))
{
String highestSuperclassName = findPenultimateSuperclass(className);
Iterator iterator = _illegalPrefixes.iterator();
while (iterator.hasNext())
{
String nextPrefix = iterator.next().toString();
if (highestSuperclassName.startsWith(nextPrefix))
return false;
}
iterator = _illegalClasses.iterator();
while (iterator.hasNext())
{
String nextClass = iterator.next().toString();
if (highestSuperclassName.equals(nextClass))
return false;
}
return true;
}
return false;
|
public boolean | isPersistent(java.lang.String className)Determines if the specified className represents a persistence capable
class. A class is persistence capable only if it is directly marked as
such -- not by inheritance.
return isPersistent(className, (ClassLoader)null);
|
public boolean | isPersistent(java.lang.String className, java.lang.ClassLoader classLoader)Determines if the specified className represents a persistence capable
class. A class is persistence capable only if it is directly marked as
such -- not by inheritance.
return (getPersistenceClass(className, classLoader) != null);
|
public boolean | isPersistent(java.lang.String className, java.lang.String fieldName)Determines if the specified className and fieldName pair represent a
persistent field.
PersistenceFieldElement fieldElement =
getPersistenceField(className, fieldName);
if (fieldElement != null)
{
return (PersistenceFieldElement.PERSISTENT ==
fieldElement.getPersistenceType());
}
return false;
|
public boolean | isPersistentAllowed(java.lang.String className, java.lang.String fieldName)Returns true if the specified field can be made
persistent, false otherwise. This computation is based
on the modifier and type of the field. Fields which are non-final
and non-static and are primitive, persistence capable, or second
class objects and not arrays return true .
return isPersistentAllowed(className, null, fieldName);
|
public boolean | isPersistentAllowed(java.lang.String className, java.lang.ClassLoader classLoader, java.lang.String fieldName)Returns true if the specified field can be made
persistent, false otherwise. This computation is based
on the modifier and type of the field. Fields which are non-final
and non-static and are primitive, persistence capable, byte arrays, or
second class objects and not arrays return true .
int modifier = getModifiers(className, fieldName);
if (!Modifier.isStatic(modifier) && !Modifier.isFinal(modifier))
{
return isPersistentTypeAllowed(
getFieldType(className, fieldName), classLoader);
}
return false;
|
protected boolean | isPersistentTypeAllowed(java.lang.String className, java.lang.ClassLoader classLoader)Returns true if the a field of the specified class or
type can be made persistent, false otherwise. Fields
which are primitive, persistence capable, byte arrays, or second
class objects and not arrays return true .
return (isPrimitive(className) || isSecondClassObject(className) ||
isByteArray(className) || isPersistent(className, classLoader));
|
public boolean | isPrimitive(java.lang.String className, java.lang.String fieldName)Determines if a field with the specified fieldName in the class
with the specified className has a primitive type.
return isPrimitive(getFieldType(className, fieldName));
|
protected boolean | isPrimitive(java.lang.String className)Determines if the specified className represents a primitive type.
return ((className != null) &&
JavaTypeHelper.getPrimitiveClass(className) != null);
|
public boolean | isSecondClassObject(java.lang.String className)Determines if the specified className represents a second class object.
For this release, the class name is checked against a list of supported
second class objects since user-defined second class objects are not
supported.
return _scoClasses.contains(className);
|
public abstract boolean | isSerializable(java.lang.Object fieldElement)Determines if the specified field element has a serializable type.
A type is serializable if it is a primitive type, a class that
implements java.io.Serializable or an interface that inherits from
java.io.Serializable.
Note, the field element is a model specific field representation as
returned by a getField call executed on the same model instance.
|
public boolean | isValidKeyType(java.lang.String className, java.lang.String fieldName)Determines if the specified className and fieldName pair represent a
field which has a type which is valid for key fields. Valid key
field types include non-collection SCOs (wrappers, Date, Time, etc.)
and primitives.
String fieldType = getFieldType(className, fieldName);
if (fieldType == null)
fieldType = getType(getInheritedField(className, fieldName));
return (isPrimitive(fieldType) ||
(isSecondClassObject(fieldType) && !isCollection(fieldType)));
|
public void | lockFile(java.lang.String className)
|
public boolean | parse(java.lang.String className)Parses the combination of java (or class) information and mapping/jdo
information by running through a subset of the full validation check
and aborting (and returning false at the first error or
warning.
return new ModelValidator(this, className, getMessages()).parseCheck();
|
public void | removeFieldElement(PersistenceFieldElement element)Removes the specified PersistenceFieldElement from its declaring
class. This method is added so that there is a common way to do this
which checks if the argument is a relationship element with an inverse
(in which case the inverse should first be cleared). This should
really be handled by the jdo model directly, but the removeField method
doesn't have access to the Model which is necessary for setting
(or clearing) inverse relationships.
if (element != null)
{
if (element instanceof RelationshipElement)
{
((RelationshipElement)element).setInverseRelationship(null,
this);
}
element.getDeclaringClass().removeField(element);
}
|
public void | removeFromCache(java.lang.String className)Removes the class with the supplied name from the cache of
classes known to be non PC.
The next call getMappingClass will determine the status of the class.
synchronized (this._classes)
{
// remove the class from the set of classes known to be non PC
_nonPCClasses.remove(className);
}
|
public void | removeResourcesFromCaches(java.lang.ClassLoader classLoader)Removes the classes cached with the specified class loader from all
caches.
This implementation does nothing, but subclasses (such as RuntimeModel)
can override this method if they support a class loader cache.
// Do nothing in the top-level model.
|
protected void | removeResourcesFromCaches(java.util.Collection classNames)Removes the specified classes from all caches. The specified
collection includes the fully qualified class names of the classes
to be removed. The method removes each class from the cache of
MappingClassElements and the set of classes known to be non
PC. Furthermore it removes the SchemaElement associated with this
class from the SchemaElement cache. The next call getMappingClass
will determine the status of the classes.
if (classNames == null)
return;
synchronized (this._classes)
{
for (Iterator i = classNames.iterator(); i.hasNext();)
{
String className = (String)i.next();
MappingClassElement mapping =
(MappingClassElement)_classes.get(className);
// If the cache has a MappingClassElement with the specified
// className, get its databaseRoot and remove the corresonding
// SchemaElement from the SchemaElement cache.
if (mapping != null)
SchemaElement.removeFromCache(mapping.getDatabaseRoot());
// remove the corresponding MappingClassElement from cache
_classes.remove(className);
// remove the class from the set of classes known to be non PC
_nonPCClasses.remove(className);
}
}
|
public boolean | shouldBePersistent(java.lang.String className, java.lang.String fieldName)Returns true if the specified field should be made
persistent (i.e. does it make sense), false otherwise.
This computation is based solely on the modifier: those which are not
volatile return true .
return !Modifier.isVolatile(getModifiers(className, fieldName));
|
public void | storeMappingClass(com.sun.jdo.api.persistence.model.mapping.MappingClassElement mappingClass)Stores the supplied MappingClassElement to an xml file, creating the
file if necessary. The caller is responsible for updating the cache
by calling updateKeyForClass, if necessary.
if (mappingClass != null)
{
String className = mappingClass.getName();
OutputStream stream = ((className == null) ? null :
createFile(className, getFileName(className),
MappingClassElement.MAPPING_EXTENSION));
storeMappingClass(mappingClass, stream);
}
|
public void | storeMappingClass(com.sun.jdo.api.persistence.model.mapping.MappingClassElement mappingClass, java.io.OutputStream stream)Stores the supplied MappingClassElement to an xml file in the
specified output stream. The caller is responsible for updating
the cache by calling updateKeyForClass, if necessary.
if (mappingClass != null)
{
String className = mappingClass.getName();
if (stream != null)
{
XMLOutputStream xmlOutput = new XMLOutputStream(stream);
try
{
mappingClass.preArchive(); // call pre archive hook
xmlOutput.writeObject(mappingClass);
// update modified flags for the mapping and persistence
// classes after save
mappingClass.setModified(false);
getPersistenceClass(mappingClass).setModified(false);
}
catch (ModelException e)
{
// MBO: print reason to logger
LogHelperModel.getLogger().log(Logger.WARNING,
e.getMessage());
}
finally
{
if (xmlOutput != null)
xmlOutput.close();
unlockFile(stream, className);
}
return;
}
throw new IOException(I18NHelper.getMessage(getMessages(),
"file.cannot_save", className)); // NOI18N
}
|
public void | storeMappingClass(java.lang.String className)Stores the MappingClassElement for the specified class name to an xml
file, creating the file if necessary. The MappingClassElement must be
present in the HashMap of classes known by the Model in order to stored.
MappingClassElement mappingClass = null;
synchronized (this._classes)
{
mappingClass = (MappingClassElement)_classes.get(className);
}
storeMappingClass(mappingClass);
|
public void | unlockFile(java.io.OutputStream stream, java.lang.String className)
unlockFile(className);
if (stream != null)
stream.close();
|
public void | unlockFile(java.lang.String className)
|
public void | updateKeyForClass(com.sun.jdo.api.persistence.model.mapping.MappingClassElement mappingClass, java.lang.String oldName)Updates the key in the cache for the supplied MappingClassElement.
// need to synchronize _classes access here
// (for details see getMappingClass)
synchronized (this._classes)
{
// remove the old key from the cache
if (oldName != null)
_classes.remove(oldName);
// store the class under the new key in the cache
if (mappingClass != null)
{
String className = mappingClass.getName();
_classes.put(className, mappingClass);
// ensure that the name of the mappingClass does not occur
// in the list of classes known to be non PC
_nonPCClasses.remove(className);
}
}
|
public java.util.Collection | validate(java.lang.String className, java.util.ResourceBundle bundle)Validates the combination of java (or class) information and mapping/jdo
information by running through the full validation check and returning
a collection of ModelValidationExceptions containing any errors or
warnings encountered.
return validate(className, null, bundle);
|
public java.util.Collection | validate(java.lang.String className, java.lang.ClassLoader classLoader, java.util.ResourceBundle bundle)Validates the combination of java (or class) information and mapping/jdo
information by running through the full validation check and returning
a collection of ModelValidationExceptions containing any errors or
warnings encountered.
return new ModelValidator(this, className, classLoader,
((bundle == null) ? getMessages() : bundle)).fullValidationCheck();
|