Esempio n. 1
0
  // copied and adapted from OJB's MtoNBroker
  protected void updateMtoNRelation(PersistenceBroker pb, RelationTupleInfo tupleInfo) {
    DomainObject obj1 = tupleInfo.obj1;
    DomainObject obj2 = tupleInfo.obj2;

    ClassDescriptor cld1 = pb.getDescriptorRepository().getDescriptorFor(obj1.getClass());
    CollectionDescriptor cod = cld1.getCollectionDescriptorByName(tupleInfo.colNameOnObj1);
    if (cod == null) {
      // try the mapping on the other object
      cld1 = pb.getDescriptorRepository().getDescriptorFor(obj2.getClass());
      cod = cld1.getCollectionDescriptorByName(tupleInfo.colNameOnObj2);

      // switch objects
      obj1 = tupleInfo.obj2;
      obj2 = tupleInfo.obj1;
    }

    String[] oidColumns = new String[2];
    oidColumns[0] = cod.getFksToThisClass()[0];
    oidColumns[1] = cod.getFksToItemClass()[0];

    ValueContainer[] oidValues = new ValueContainer[2];
    oidValues[0] = new ValueContainer(obj1.getOid(), OID_JDBC_TYPE);
    oidValues[1] = new ValueContainer(obj2.getOid(), OID_JDBC_TYPE);

    String table = cod.getIndirectionTable();

    // always remove the tuple
    String sqlStmt = pb.serviceSqlGenerator().getDeleteMNStatement(table, oidColumns, null);
    pb.serviceJdbcAccess().executeUpdateSQL(sqlStmt, cld1, oidValues, null);

    // if it was not to remove but to add, then add it
    // this "delete-first, add-after" serves to ensure that we can add
    // multiple times
    // the same tuple to a relation and still have the Set semantics for the
    // relation.
    if (!tupleInfo.remove) {
      sqlStmt = pb.serviceSqlGenerator().getInsertMNStatement(table, oidColumns, EMPTY_ARRAY);
      pb.serviceJdbcAccess().executeUpdateSQL(sqlStmt, cld1, oidValues, null);
    }
  }
Esempio n. 2
0
 @Override
 public int hashCode() {
   return relation.hashCode() + obj1.hashCode() + obj2.hashCode();
 }
Esempio n. 3
0
 protected static ItemGuidIF getItemGuidIF(final ItemIF itemIF, final DomainObject domainObject) {
   final ItemGuidIF itemGuidIF = new ItemGuid(itemIF);
   itemGuidIF.setLocation(domainObject.getClass().getName() + domainObject.getExternalId());
   itemGuidIF.setPermaLink(false);
   return itemGuidIF;
 }