本文整理汇总了Java中org.apache.ojb.broker.metadata.ClassDescriptor.getClassNameOfObject方法的典型用法代码示例。如果您正苦于以下问题:Java ClassDescriptor.getClassNameOfObject方法的具体用法?Java ClassDescriptor.getClassNameOfObject怎么用?Java ClassDescriptor.getClassNameOfObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ojb.broker.metadata.ClassDescriptor
的用法示例。
在下文中一共展示了ClassDescriptor.getClassNameOfObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRelationshipPrefetcher
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
/**
* create either a CollectionPrefetcher or a ReferencePrefetcher
*/
public RelationshipPrefetcher createRelationshipPrefetcher(ClassDescriptor anOwnerCld, String aRelationshipName)
{
ObjectReferenceDescriptor ord;
ord = anOwnerCld.getCollectionDescriptorByName(aRelationshipName);
if (ord == null)
{
ord = anOwnerCld.getObjectReferenceDescriptorByName(aRelationshipName);
if (ord == null)
{
throw new PersistenceBrokerException("Relationship named '" + aRelationshipName
+ "' not found in owner class " + (anOwnerCld != null ? anOwnerCld.getClassNameOfObject() : null));
}
}
return createRelationshipPrefetcher(ord);
}
示例2: getStatement
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
/** Return SELECT clause for object existence call */
public String getStatement()
{
if(sql == null)
{
StringBuffer stmt = new StringBuffer(128);
ClassDescriptor cld = getClassDescriptor();
FieldDescriptor[] fieldDescriptors = cld.getPkFields();
if(fieldDescriptors == null || fieldDescriptors.length == 0)
{
throw new OJBRuntimeException("No PK fields defined in metadata for " + cld.getClassNameOfObject());
}
FieldDescriptor field = fieldDescriptors[0];
stmt.append(SELECT);
stmt.append(field.getColumnName());
stmt.append(FROM);
stmt.append(cld.getFullTableName());
appendWhereClause(cld, false, stmt);
sql = stmt.toString();
}
return sql;
}
示例3: extractOjbConcreteClass
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
protected String extractOjbConcreteClass(ClassDescriptor cld, ResultSet rs, Map row)
{
FieldDescriptor fld = m_cld.getOjbConcreteClassField();
if (fld == null)
{
return null;
}
try
{
Object tmp = fld.getJdbcType().getObjectFromColumn(rs, fld.getColumnName());
// allow field-conversion for discriminator column too
String result = (String) fld.getFieldConversion().sqlToJava(tmp);
result = result != null ? result.trim() : null;
if (result == null || result.length() == 0)
{
throw new PersistenceBrokerException(
"ojbConcreteClass field for class " + cld.getClassNameOfObject()
+ " returned null or 0-length string");
}
else
{
/*
arminw: Make sure that we don't read discriminator field twice from the ResultSet.
*/
row.put(fld.getColumnName(), result);
return result;
}
}
catch(SQLException e)
{
throw new PersistenceBrokerException("Unexpected error while try to read 'ojbConcretClass'" +
" field from result set using column name " + fld.getColumnName() + " main class" +
" was " + m_cld.getClassNameOfObject(), e);
}
}
示例4: setFKField
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
/**
* Set the FK value on the target object, extracted from the referenced object. If the referenced object was
* <i>null</i> the FK values were set to <i>null</i>, expect when the FK field was declared as PK.
*
* @param targetObject real (non-proxy) target object
* @param cld {@link ClassDescriptor} of the real target object
* @param rds An {@link ObjectReferenceDescriptor} or {@link CollectionDescriptor}
* @param referencedObject The referenced object or <i>null</i>
*/
private void setFKField(Object targetObject, ClassDescriptor cld, ObjectReferenceDescriptor rds, Object referencedObject)
{
ValueContainer[] refPkValues;
FieldDescriptor fld;
FieldDescriptor[] objFkFields = rds.getForeignKeyFieldDescriptors(cld);
if (objFkFields == null)
{
throw new PersistenceBrokerException("No foreign key fields defined for class '"+cld.getClassNameOfObject()+"'");
}
if(referencedObject == null)
{
refPkValues = null;
}
else
{
Class refClass = proxyFactory.getRealClass(referencedObject);
ClassDescriptor refCld = getClassDescriptor(refClass);
refPkValues = brokerHelper.getKeyValues(refCld, referencedObject, false);
}
for (int i = 0; i < objFkFields.length; i++)
{
fld = objFkFields[i];
/*
arminw:
we set the FK value when the extracted PK fields from the referenced object are not null at all
or if null, the FK field was not a PK field of target object too.
Should be ok, because the values of the extracted PK field values should never be null and never
change, so it doesn't matter if the target field is a PK too.
*/
if(refPkValues != null || !fld.isPrimaryKey())
{
fld.getPersistentField().set(targetObject, refPkValues != null ? refPkValues[i].getValue(): null);
}
}
}
示例5: buildNewObjectInstance
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
/**
* Builds a new instance for the class represented by the given class descriptor.
*
* @param cld The class descriptor
* @return The instance
*/
public static Object buildNewObjectInstance(ClassDescriptor cld)
{
Object result = null;
// If either the factory class and/or factory method is null,
// just follow the normal code path and create via constructor
if ((cld.getFactoryClass() == null) || (cld.getFactoryMethod() == null))
{
try
{
// 1. create an empty Object (persistent classes need a public default constructor)
Constructor con = cld.getZeroArgumentConstructor();
if(con == null)
{
throw new ClassNotPersistenceCapableException(
"A zero argument constructor was not provided! Class was '" + cld.getClassNameOfObject() + "'");
}
result = ConstructorHelper.instantiate(con);
}
catch (InstantiationException e)
{
throw new ClassNotPersistenceCapableException(
"Can't instantiate class '" + cld.getClassNameOfObject()+"'");
}
}
else
{
try
{
// 1. create an empty Object by calling the no-parms factory method
Method method = cld.getFactoryMethod();
if (Modifier.isStatic(method.getModifiers()))
{
// method is static so call it directly
result = method.invoke(null, null);
}
else
{
// method is not static, so create an object of the factory first
// note that this requires a public no-parameter (default) constructor
Object factoryInstance = cld.getFactoryClass().newInstance();
result = method.invoke(factoryInstance, null);
}
}
catch (Exception ex)
{
throw new PersistenceBrokerException("Unable to build object instance of class '"
+ cld.getClassNameOfObject() + "' from factory:" + cld.getFactoryClass()
+ "." + cld.getFactoryMethod(), ex);
}
}
return result;
}
示例6: storeToDb
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
/**
* I pulled this out of internal store so that when doing multiple table
* inheritance, i can recurse this function.
*
* @param obj
* @param cld
* @param oid BRJ: what is it good for ???
* @param insert
* @param ignoreReferences
*/
private void storeToDb(Object obj, ClassDescriptor cld, Identity oid, boolean insert, boolean ignoreReferences)
{
// 1. link and store 1:1 references
storeReferences(obj, cld, insert, ignoreReferences);
Object[] pkValues = oid.getPrimaryKeyValues();
if (!serviceBrokerHelper().assertValidPksForStore(cld.getPkFields(), pkValues))
{
// BRJ: fk values may be part of pk, but the are not known during
// creation of Identity. so we have to get them here
pkValues = serviceBrokerHelper().getKeyValues(cld, obj);
if (!serviceBrokerHelper().assertValidPksForStore(cld.getPkFields(), pkValues))
{
String append = insert ? " on insert" : " on update" ;
throw new PersistenceBrokerException("assertValidPkFields failed for Object of type: " + cld.getClassNameOfObject() + append);
}
}
// get super class cld then store it with the object
/*
now for multiple table inheritance
1. store super classes, topmost parent first
2. go down through heirarchy until current class
3. todo: store to full extent?
// arminw: TODO: The extend-attribute feature dosn't work, should we remove this stuff?
This if-clause will go up the inheritance heirarchy to store all the super classes.
The id for the top most super class will be the id for all the subclasses too
*/
if(cld.getSuperClass() != null)
{
ClassDescriptor superCld = getDescriptorRepository().getDescriptorFor(cld.getSuperClass());
storeToDb(obj, superCld, oid, insert);
// arminw: why this?? I comment out this section
// storeCollections(obj, cld.getCollectionDescriptors(), insert);
}
// 2. store primitive typed attributes (Or is THIS step 3 ?)
// if obj not present in db use INSERT
if (insert)
{
dbAccess.executeInsert(cld, obj);
if(oid.isTransient())
{
// Create a new Identity based on the current set of primary key values.
oid = serviceIdentity().buildIdentity(cld, obj);
}
}
// else use UPDATE
else
{
try
{
dbAccess.executeUpdate(cld, obj);
}
catch(OptimisticLockException e)
{
// ensure that the outdated object be removed from cache
objectCache.remove(oid);
throw e;
}
}
// cache object for symmetry with getObjectByXXX()
// Add the object to the cache.
objectCache.doInternalCache(oid, obj, ObjectCacheInternal.TYPE_WRITE);
// 3. store 1:n and m:n associations
if(!ignoreReferences) storeCollections(obj, cld, insert);
}