|
|
|
|
@ -1,9 +1,16 @@
|
|
|
|
|
package siprp.database.cayenne.objects;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.text.DateFormat;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import org.apache.cayenne.CayenneDataObject;
|
|
|
|
|
import org.apache.cayenne.ObjectId;
|
|
|
|
|
import org.apache.cayenne.PersistenceState;
|
|
|
|
|
|
|
|
|
|
import siprp.database.cayenne.providers.MainDAO;
|
|
|
|
|
@ -107,4 +114,87 @@ public class BaseObject extends CayenneDataObject implements Comparable<BaseObje
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private <OBJ_CLASS extends BaseObject> List<OBJ_CLASS>getNtoN( String relation, String toGet )
|
|
|
|
|
{
|
|
|
|
|
List<OBJ_CLASS> result = new LinkedList<OBJ_CLASS>();
|
|
|
|
|
for( BaseObject o : (List<? extends BaseObject>) super.readProperty(relation) )
|
|
|
|
|
{
|
|
|
|
|
OBJ_CLASS toGetObj = (OBJ_CLASS) o.readProperty( toGet );
|
|
|
|
|
if( null == toGetObj.readProperty( "deleted_date" ) )
|
|
|
|
|
{
|
|
|
|
|
result.add(toGetObj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Object readProperty(String propertyName) {
|
|
|
|
|
return (propertyName != null && propertyName.endsWith("Array") ) ? getReferringObjects(propertyName) : super.readProperty(propertyName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private <OBJ_CLASS extends BaseObject > boolean isRelational( OBJ_CLASS object )
|
|
|
|
|
{
|
|
|
|
|
boolean result = false;
|
|
|
|
|
ObjectId id = object.getObjectId();
|
|
|
|
|
if( id != null && !id.isTemporary() )
|
|
|
|
|
{
|
|
|
|
|
Map<String,Object> ids = id.getIdSnapshot();
|
|
|
|
|
if( ids != null && ids.size() == 2 )
|
|
|
|
|
{
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private <OBJ_CLASS extends BaseObject > boolean isRelDeleted( OBJ_CLASS object )
|
|
|
|
|
{
|
|
|
|
|
boolean result = false;
|
|
|
|
|
if( object != null )
|
|
|
|
|
{
|
|
|
|
|
for( Method method : object.getClass().getMethods() )
|
|
|
|
|
{
|
|
|
|
|
if( method.getName().startsWith("getTo") )
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Object returned = method.invoke(object);
|
|
|
|
|
if( returned != null && (returned instanceof BaseObject ) )
|
|
|
|
|
{
|
|
|
|
|
result |= null != ((BaseObject)returned).readProperty("deletedDate");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
private <OBJ_CLASS extends BaseObject> List<OBJ_CLASS> getReferringObjects( String arrayProperty )
|
|
|
|
|
{
|
|
|
|
|
List<OBJ_CLASS> result = new LinkedList<OBJ_CLASS>();
|
|
|
|
|
Boolean isRel = null;
|
|
|
|
|
for( OBJ_CLASS o : (List<OBJ_CLASS>) super.readProperty(arrayProperty) )
|
|
|
|
|
{
|
|
|
|
|
if( isRel == null )
|
|
|
|
|
{
|
|
|
|
|
isRel = isRelational( o );
|
|
|
|
|
}
|
|
|
|
|
if( null == o.readProperty( "deletedDate" ) )
|
|
|
|
|
{
|
|
|
|
|
if( !isRel || !isRelDeleted( o ) )
|
|
|
|
|
{
|
|
|
|
|
result.add(o);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|