本文整理汇总了Java中org.apache.ojb.broker.core.proxy.ProxyHelper.getRealObject方法的典型用法代码示例。如果您正苦于以下问题:Java ProxyHelper.getRealObject方法的具体用法?Java ProxyHelper.getRealObject怎么用?Java ProxyHelper.getRealObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ojb.broker.core.proxy.ProxyHelper
的用法示例。
在下文中一共展示了ProxyHelper.getRealObject方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isNull
import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入方法依赖的package包/类
/**
* This method is a OJB Proxy-safe way to test for null on a proxied object that may or may not be materialized yet.
* It is safe
* to use on a proxy (materialized or non-materialized) or on a non-proxy (ie, regular object). Note that this will
* force a
* materialization of the proxy if the object is a proxy and unmaterialized.
*
* @param object - any object, proxied or not, materialized or not
* @return true if the object (or underlying materialized object) is null, false otherwise
*/
public static boolean isNull(Object object) {
// regardless, if its null, then its null
if (object == null) {
return true;
}
// only try to materialize the object to see if its null if this is a
// proxy object
if (ProxyHelper.isProxy(object) || ProxyHelper.isCollectionProxy(object)) {
if (ProxyHelper.getRealObject(object) == null) {
return true;
}
}
// JPA does not provide a way to determine if an object is a proxy, instead we invoke
// the equals method and catch an EntityNotFoundException
try {
object.equals(null);
} catch (EntityNotFoundException e) {
return true;
}
return false;
}
示例2: getObjectByIdentity
import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入方法依赖的package包/类
/**
* @see org.apache.ojb.otm.OTMConnection#getObjectByIdentity(Identity, int)
*/
public Object getObjectByIdentity(Identity oid, int lock) throws LockingException
{
checkTransaction("getObjectByIdentity");
Object userObject;
Object cacheObject;
cacheObject = _pb.getObjectByIdentity(oid);
if (cacheObject == null)
{
// Possibly the object was inserted in this transaction
// and was not stored to database yet
userObject = _editingContext.lookup(oid);
}
else
{
userObject = getUserObject(oid, cacheObject);
// userObject from editing context may be proxy
userObject = ProxyHelper.getRealObject(userObject);
_editingContext.insert(oid, userObject, lock);
}
return userObject;
}
示例3: ObjectEnvelope
import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入方法依赖的package包/类
/**
* Create a wrapper by providing an Object.
*/
public ObjectEnvelope(ObjectEnvelopeTable buffer, Identity oid, Object obj, boolean isNewObject)
{
this.linkEntryList = new ArrayList();
this.buffer = buffer;
this.oid = oid;
// TODO: do we really need to materialize??
myObj = ProxyHelper.getRealObject(obj);
prepareInitialState(isNewObject);
/*
TODO: is it possible to improve this? Take care that "new"
objects should support "persistence by reachability" too
(detection of new/persistent reference objects after maon object lock)
*/
beforeImage = buildObjectImage(getBroker());
}
示例4: getForeignKeyValues
import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入方法依赖的package包/类
/**
* Returns an Object array of all FK field values of the specified object.
* If the specified object is an unmaterialized Proxy, it will be materialized
* to read the FK values.
*
* @throws MetadataException if an error occours while accessing ForeingKey values on obj
*/
public Object[] getForeignKeyValues(Object obj, ClassDescriptor mif)
throws PersistenceBrokerException
{
FieldDescriptor[] fks = getForeignKeyFieldDescriptors(mif);
// materialize object only if FK fields are declared
if(fks.length > 0) obj = ProxyHelper.getRealObject(obj);
Object[] result = new Object[fks.length];
for (int i = 0; i < result.length; i++)
{
FieldDescriptor fmd = fks[i];
PersistentField f = fmd.getPersistentField();
// BRJ: do NOT convert.
// conversion is done when binding the sql-statement
//
// FieldConversion fc = fmd.getFieldConversion();
// Object val = fc.javaToSql(f.get(obj));
result[i] = f.get(obj);
}
return result;
}
示例5: refreshAttachment
import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入方法依赖的package包/类
/**
* The attachment BO is proxied in OJB. For some reason when an attachment does not yet exist,
* refreshReferenceObject is not returning null and the proxy cannot be materialized. So, this method exists to
* properly handle the proxied attachment BO. This is a hack and should be removed post JPA migration.
*/
protected void refreshAttachment() {
if (KRADUtils.isNull(attachment)) {
this.refreshReferenceObject("attachment");
final boolean isProxy = attachment != null && ProxyHelper.isProxy(attachment);
if (isProxy && ProxyHelper.getRealObject(attachment) == null) {
attachment = null;
}
}
}
示例6: refreshAttachmentList
import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入方法依赖的package包/类
protected void refreshAttachmentList() {
if (KRADUtils.isNull(attachments)) {
this.refreshReferenceObject("attachments");
final boolean isProxy = attachments != null && ProxyHelper.isProxy(attachments);
if (isProxy && ProxyHelper.getRealObject(attachments) == null) {
attachments = null;
}
}
}
示例7: updateExtensionRecord
import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入方法依赖的package包/类
/**
* Determines if an extension record is mapped up and exists for the current record. If so then updates the version number,
* object id, and clears the primary keys so they will be relinked when storing the main record
*
* @param newFiscalYear fiscal year to set
* @param currentRecord main record with possible extension reference
*/
protected void updateExtensionRecord(Integer newFiscalYear, PersistableBusinessObject currentRecord) throws Exception {
// check if reference is mapped up
if ( !hasExtension() ) {
return;
}
// try to retrieve extension record
currentRecord.refreshReferenceObject(OLEPropertyConstants.EXTENSION);
PersistableBusinessObject extension = currentRecord.getExtension();
// if found then update fields
if (ObjectUtils.isNotNull(extension)) {
extension = (PersistableBusinessObject)ProxyHelper.getRealObject(extension);
extension.setVersionNumber(ONE);
extension.setObjectId(java.util.UUID.randomUUID().toString());
// since this could be a new object (no extension object present on the source record)
// we need to set the keys
// But...we only need to do this if this was a truly new object, which we can tell by checking
// the fiscal year field
if ( ((FiscalYearBasedBusinessObject)extension).getUniversityFiscalYear() == null ) {
for ( String pkField : getPrimaryKeyPropertyNames() ) {
PropertyUtils.setSimpleProperty(extension, pkField, PropertyUtils.getSimpleProperty(currentRecord, pkField));
}
}
((FiscalYearBasedBusinessObject)extension).setUniversityFiscalYear(newFiscalYear);
}
}
示例8: updateExtensionRecord
import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入方法依赖的package包/类
/**
* Determines if an extension record is mapped up and exists for the current record. If so then updates the version number,
* object id, and clears the primary keys so they will be relinked when storing the main record
*
* @param newFiscalYear fiscal year to set
* @param currentRecord main record with possible extension reference
*/
protected void updateExtensionRecord(Integer newFiscalYear, PersistableBusinessObject currentRecord) throws Exception {
// check if reference is mapped up
if ( !hasExtension() ) {
return;
}
// try to retrieve extension record
currentRecord.refreshReferenceObject(KFSPropertyConstants.EXTENSION);
PersistableBusinessObject extension = currentRecord.getExtension();
// if found then update fields
if (ObjectUtils.isNotNull(extension)) {
extension = (PersistableBusinessObject)ProxyHelper.getRealObject(extension);
extension.setVersionNumber(ONE);
extension.setObjectId(java.util.UUID.randomUUID().toString());
// since this could be a new object (no extension object present on the source record)
// we need to set the keys
// But...we only need to do this if this was a truly new object, which we can tell by checking
// the fiscal year field
if ( ((FiscalYearBasedBusinessObject)extension).getUniversityFiscalYear() == null ) {
for ( String pkField : getPrimaryKeyPropertyNames() ) {
PropertyUtils.setSimpleProperty(extension, pkField, PropertyUtils.getSimpleProperty(currentRecord, pkField));
}
}
((FiscalYearBasedBusinessObject)extension).setUniversityFiscalYear(newFiscalYear);
}
}
示例9: refreshAttachment
import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入方法依赖的package包/类
/**
* The attachment BO is proxied in OJB. For some reason when an attachment does not yet exist,
* refreshReferenceObject is not returning null and the proxy cannot be materialized. So, this method exists to
* properly handle the proxied attachment BO. This is a hack and should be removed post JPA migration.
*/
protected void refreshAttachment() {
if (ObjectUtils.isNull(attachment)) {
this.refreshReferenceObject("attachment");
final boolean isProxy = attachment != null && ProxyHelper.isProxy(attachment);
if (isProxy && ProxyHelper.getRealObject(attachment) == null) {
attachment = null;
}
}
}
示例10: refreshAttachmentList
import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入方法依赖的package包/类
protected void refreshAttachmentList() {
if (ObjectUtils.isNull(attachments)) {
this.refreshReferenceObject("attachments");
final boolean isProxy = attachments != null && ProxyHelper.isProxy(attachments);
if (isProxy && ProxyHelper.getRealObject(attachments) == null) {
attachments = null;
}
}
}
示例11: cascadeInsertCollectionReferences
import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入方法依赖的package包/类
private void cascadeInsertCollectionReferences(ObjectEnvelope source, List descriptor, List alreadyPrepared)
{
// PersistenceBroker pb = getTransaction().getBroker();
for(int i = 0; i < descriptor.size(); i++)
{
CollectionDescriptor col = (CollectionDescriptor) descriptor.get(i);
Object collOrArray = col.getPersistentField().get(source.getObject());
CollectionProxy proxy = ProxyHelper.getCollectionProxy(collOrArray);
/*
on insert we perform only materialized collection objects. This should be
sufficient, because in method #cascadingDependents() we make sure that on
move of unmaterialized collection objects the proxy was materialized if needed.
*/
if(proxy == null && collOrArray != null)
{
Iterator it = BrokerHelper.getCollectionIterator(collOrArray);
while(it.hasNext())
{
Object colObj = it.next();
if(colObj != null)
{
RuntimeObject rt = new RuntimeObject(colObj, getTransaction());
Identity oid = rt.getIdentity();
/*
arminw:
only when the main object need insert we start with FK assignment
of the 1:n and m:n relations. If the main objects need update (was already persisted)
it should be handled by the object state detection in ObjectEnvelope
*/
if(source.needsInsert())
{
/*
arminw:
TODO: what is the valid way to go, when the collection object itself is
a unmaterialized proxy object? Think in this case we should materialize the
object when the main object needs insert, because we have to assign the FK values
to the main object
*/
colObj = ProxyHelper.getRealObject(colObj);
ObjectEnvelope oe = getByIdentity(oid);
if(oe == null)
{
getTransaction().lockAndRegister(rt, Transaction.WRITE, false, getTransaction().getRegistrationList());
oe = getByIdentity(oid);
}
if(col.isMtoNRelation())
{
// the main objects needs insert, thus add new m:n link
addM2NLinkEntry(col, source.getObject(), colObj);
}
else
{
// we mark collection reference for linking
oe.addLinkOneToN(col, source.getObject(), false);
/*
arminw: The referenced object could be already persisted, so we have
to dirty it to guarantee the setting of the FK (linking)
*/
oe.setModificationState(oe.getModificationState().markDirty());
}
cascadeInsertFor(oe, alreadyPrepared);
}
}
}
}
}
}
示例12: cascadeDeleteCollectionReferences
import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入方法依赖的package包/类
private void cascadeDeleteCollectionReferences(ObjectEnvelope source, List descriptor, List alreadyPrepared)
{
PersistenceBroker pb = getTransaction().getBroker();
for(int i = 0; i < descriptor.size(); i++)
{
CollectionDescriptor col = (CollectionDescriptor) descriptor.get(i);
boolean cascadeDelete = getTransaction().cascadeDeleteFor(col);
Object collOrArray = col.getPersistentField().get(source.getObject());
// TODO: remove cast
CollectionProxyDefaultImpl proxy = (CollectionProxyDefaultImpl) ProxyHelper.getCollectionProxy(collOrArray);
// on delete we have to materialize dependent objects
if(proxy != null)
{
collOrArray = proxy.getData();
}
if(collOrArray != null)
{
Iterator it = BrokerHelper.getCollectionIterator(collOrArray);
while(it.hasNext())
{
Object colObj = ProxyHelper.getRealObject(it.next());
Identity oid = pb.serviceIdentity().buildIdentity(colObj);
ObjectEnvelope colMod = get(oid, colObj, false);
if(cascadeDelete)
{
colMod.setModificationState(colMod.getModificationState().markDelete());
cascadeDeleteFor(colMod, alreadyPrepared);
}
else
{
if(!col.isMtoNRelation())
{
colMod.addLinkOneToN(col, source.getObject(), true);
colMod.setModificationState(colMod.getModificationState().markDirty());
}
}
if(col.isMtoNRelation())
{
addM2NUnlinkEntry(col, source.getObject(), colObj);
}
}
}
}
}
示例13: getRealObject
import org.apache.ojb.broker.core.proxy.ProxyHelper; //导入方法依赖的package包/类
public Object getRealObject()
{
return ProxyHelper.getRealObject(getObject());
}