public void setup() throws Exception {

    DatabaseLogin login;
    login = (DatabaseLogin) getSession().getLogin().clone();
    server = new Server(login);
    server.serverSession.setLogLevel(getSession().getLogLevel());
    server.serverSession.setLog(getSession().getLog());

    server.copyDescriptors(getSession());
    ClassDescriptor d = (server.serverSession).getClassDescriptor(BigBadObject.class);
    DatabaseMapping m;

    Vector v = d.getMappings();
    int mappings = v.size();
    int i = 0;
    while (i < mappings) {
      m = (DatabaseMapping) v.get(i);
      m.setWeight(new Integer(Integer.MAX_VALUE - 1));
      i++;
    }

    m = d.getMappingForAttributeName("number02");
    m.setWeight(new Integer(Integer.MAX_VALUE));

    server.login();
    server.serverSession.setLogLevel(getSession().getLogLevel());
    server.serverSession.setLog(getSession().getLog());
  }
  /** INTERNAL: Get a value from the object and set that in the respective field of the row. */
  @Override
  public Object valueFromObject(Object object, DatabaseField field, AbstractSession session) {
    // First check if the value can be obtained from the value holder's row.
    AbstractRecord referenceRow =
        getIndirectionPolicy().extractReferenceRow(getAttributeValueFromObject(object));
    if (referenceRow != null) {
      Object value = referenceRow.get(field);

      // Must ensure the classification to get a cache hit.
      try {
        value = session.getDatasourcePlatform().convertObject(value, getFieldClassification(field));
      } catch (ConversionException e) {
        throw ConversionException.couldNotBeConverted(this, getDescriptor(), e);
      }

      return value;
    }

    // 2.5.1.6 PWK.  added to support batch reading on variable one to ones
    Object referenceObject = getRealAttributeValueFromObject(object, session);
    String queryKeyName = (String) getSourceToTargetQueryKeyNames().get(field);
    ClassDescriptor objectDescriptor = session.getDescriptor(referenceObject.getClass());
    DatabaseField targetField =
        objectDescriptor.getObjectBuilder().getTargetFieldForQueryKeyName(queryKeyName);

    if (targetField == null) {
      return null;
    }

    return objectDescriptor
        .getObjectBuilder()
        .extractValueFromObjectForField(referenceObject, targetField, session);
  }
  public void setup() {
    ConcurrentTestRefreshWithOptimisticLocking.execute = true;
    try {
      getSession().getLog().write("WARNING, some tests may take 3 minutes or more");
      getSession().getLog().flush();
    } catch (java.io.IOException e) {
    }

    try {
      DatabaseLogin login = (DatabaseLogin) getSession().getLogin().clone();
      ConcurrentTestRefreshWithOptimisticLocking.server =
          new Server(login, numThreads, numThreads + 2);
      ConcurrentTestRefreshWithOptimisticLocking.server.serverSession.setSessionLog(
          getSession().getSessionLog());
      ConcurrentTestRefreshWithOptimisticLocking.server.login();
      ConcurrentTestRefreshWithOptimisticLocking.server.copyDescriptors(getSession());
      ClassDescriptor empDesc =
          this.server.serverSession.getClassDescriptor(DeadLockEmployee.class);
      this.oldVersionRefresh = empDesc.shouldOnlyRefreshCacheIfNewerVersion();
      empDesc.onlyRefreshCacheIfNewerVersion();

    } catch (ValidationException ex) {
      this.verify();
    }

    for (int count = 0; count < numThreads; ++count) {
      ConcurrentTestRefreshWithOptimisticLocking.threadList[count] =
          new Thread(new ConcurrentTestRefreshWithOptimisticLocking(false, count).runnable());
      ConcurrentTestRefreshWithOptimisticLocking.timeList[count] = System.currentTimeMillis();
    }
  }
 /**
  * INTERNAL: this returns a single expression to represent the join from the main table to all
  * child descriptor tables Only if outer joins should be printed in the where clause
  *
  * @return Expression
  */
 public Expression getTreatCriteria() {
   if (getDescriptor() == null) {
     return null;
   }
   // need to build this using just the multiple tables on this descriptor not included in the
   // parent's join expression
   Expression criteria = null;
   if (getSession().getPlatform().shouldPrintOuterJoinInWhereClause()) {
     Vector tables = getDescriptor().getTables(); // This child's tables
     ClassDescriptor parentDescriptor = this.typeExpressionBase.getDescriptor();
     int tablesSize = tables.size();
     if (parentDescriptor.hasInheritance()
         && parentDescriptor.getInheritancePolicy().hasMultipleTableChild()) {
       // look up the joins from the parent descriptor to our tables.
       for (int i = 0; i < tablesSize; i++) {
         DatabaseTable table = (DatabaseTable) tables.elementAt(i);
         Expression joinExpression =
             parentDescriptor.getInheritancePolicy().getChildrenTablesJoinExpressions().get(table);
         // Some of our tables might be the in our parent as well, so ignore the lack of a
         // joinExpression
         if (joinExpression != null) {
           joinExpression = this.baseExpression.twist(joinExpression, this);
           if (shouldUseOuterJoin()) {
             joinExpression = joinExpression.convertToUseOuterJoin();
           }
           criteria = joinExpression.and(criteria);
         }
       }
     }
   }
   return criteria;
 }
Exemplo n.º 5
0
 /**
  * Commit all of the objects of the class type in the change set. This allows for the order of the
  * classes to be processed optimally.
  */
 protected void commitNewObjectsForClassWithChangeSet(
     UnitOfWorkChangeSet uowChangeSet, Class theClass) {
   Map<ObjectChangeSet, ObjectChangeSet> newObjectChangesList =
       uowChangeSet.getNewObjectChangeSets().get(theClass);
   if (newObjectChangesList != null) { // may be no changes for that class type.
     AbstractSession session = getSession();
     ClassDescriptor descriptor = session.getDescriptor(theClass);
     List<ObjectChangeSet> newChangeSets = new ArrayList(newObjectChangesList.values());
     int size = newChangeSets.size();
     for (int index = 0; index < size; index++) {
       ObjectChangeSet changeSetToWrite = newChangeSets.get(index);
       Object objectToWrite = changeSetToWrite.getUnitOfWorkClone();
       if (!isProcessedCommit(objectToWrite)) {
         // PERF: Get the descriptor query, to avoid extra query creation.
         InsertObjectQuery commitQuery = descriptor.getQueryManager().getInsertQuery();
         if (commitQuery == null) {
           commitQuery = new InsertObjectQuery();
           commitQuery.setDescriptor(descriptor);
         } else {
           // Ensure original query has been prepared.
           commitQuery.checkPrepare(session, commitQuery.getTranslationRow());
           commitQuery = (InsertObjectQuery) commitQuery.clone();
         }
         commitQuery.setIsExecutionClone(true);
         commitQuery.setObjectChangeSet(changeSetToWrite);
         commitQuery.setObject(objectToWrite);
         commitQuery.cascadeOnlyDependentParts();
         commitQuery.setModifyRow(null);
         session.executeQuery(commitQuery);
       }
       uowChangeSet.putNewObjectInChangesList(changeSetToWrite, session);
     }
   }
 }
  /**
   * INTERNAL: Return the classification for the field contained in the mapping. This is used to
   * convert the row value to a consistent java value.
   */
  @Override
  public Class getFieldClassification(DatabaseField fieldToClassify) {
    if ((getTypeField() != null) && (fieldToClassify.equals(getTypeField()))) {
      return getTypeField().getType();
    }

    String queryKey = (String) getSourceToTargetQueryKeyNames().get(fieldToClassify);
    if (queryKey == null) {
      return null;
    }
    // Search any of the implementor descriptors for a mapping for the query-key.
    Iterator iterator =
        getReferenceDescriptor().getInterfacePolicy().getChildDescriptors().iterator();
    if (iterator.hasNext()) {
      ClassDescriptor firstChild = (ClassDescriptor) iterator.next();
      DatabaseMapping mapping = firstChild.getObjectBuilder().getMappingForAttributeName(queryKey);
      if ((mapping != null) && (mapping.isDirectToFieldMapping())) {
        return ((AbstractDirectMapping) mapping).getAttributeClassification();
      }
      QueryKey targetQueryKey = firstChild.getQueryKeyNamed(queryKey);
      if ((targetQueryKey != null) && (targetQueryKey.isDirectQueryKey())) {
        return firstChild
            .getObjectBuilder()
            .getFieldClassification(((DirectQueryKey) targetQueryKey).getField());
      }
    }
    return null;
  }
Exemplo n.º 7
0
  /** Delete all of the objects with the matching class. */
  public void deleteAllObjects(Class theClass, List objects, AbstractSession session) {
    ClassDescriptor descriptor = null;

    if (((UnitOfWorkImpl) session).shouldOrderUpdates()) { // bug 331064 - Sort the delete order
      objects = sort(theClass, objects);
    }

    int size = objects.size();
    for (int index = 0; index < size; index++) {
      Object objectToDelete = objects.get(index);
      if (objectToDelete.getClass() == theClass) {
        if (descriptor == null) {
          descriptor = session.getDescriptor(theClass);
        }
        // PERF: Get the descriptor query, to avoid extra query creation.
        DeleteObjectQuery deleteQuery = descriptor.getQueryManager().getDeleteQuery();
        if (deleteQuery == null) {
          deleteQuery = new DeleteObjectQuery();
          deleteQuery.setDescriptor(descriptor);
        } else {
          // Ensure original query has been prepared.
          deleteQuery.checkPrepare(session, deleteQuery.getTranslationRow());
          deleteQuery = (DeleteObjectQuery) deleteQuery.clone();
        }
        deleteQuery.setIsExecutionClone(true);
        deleteQuery.setObject(objectToDelete);
        session.executeQuery(deleteQuery);
      }
    }
  }
 public Object getObjectForUpdate(
     Session session,
     Object objectToUpdateBeforeChange,
     Object objectToUpdateAfterChange,
     boolean useUOW) {
   ClassDescriptor desc = session.getClassDescriptor(objectToUpdateBeforeChange);
   Record rowBeforeChange =
       desc.getObjectBuilder()
           .buildRow(objectToUpdateBeforeChange, (AbstractSession) session, WriteType.UPDATE);
   Record rowAfterChange =
       desc.getObjectBuilder()
           .buildRow(objectToUpdateAfterChange, (AbstractSession) session, WriteType.UPDATE);
   Record rowChange = new DatabaseRecord();
   getChange(
       rowChange,
       session,
       objectToUpdateBeforeChange,
       objectToUpdateAfterChange,
       desc,
       useUOW,
       WriteType.UPDATE);
   Record rowReturn = getRowForUpdate(rowChange);
   if (rowReturn != null && !rowReturn.isEmpty()) {
     Record row = new DatabaseRecord(rowAfterChange.size());
     row.putAll(rowAfterChange);
     row.putAll(rowReturn);
     return readObjectFromRow(session, desc, row);
   } else {
     return objectToUpdateAfterChange;
   }
 }
  /** @param clazzDescriptor */
  protected void iconizeTableName(final ClassDescriptor clazzDescriptor, final Session session) {
    final String alias = clazzDescriptor.getAlias();

    final String tableName = NameUtils.camelCaseToUnderscore(alias);

    LogSupport.logFine(session, "Set Tablename to {0}", tableName);
    clazzDescriptor.setTableName(tableName);
  }
 /** {@inheritDoc} */
 @Override
 public void initialize(XRServiceAdapter xrService, QueryOperation queryOperation) {
   if (descriptor != null) {
     ClassDescriptor cd = xrService.getORSession().getProject().getDescriptorForAlias(descriptor);
     databaseQuery = cd.getQueryManager().getQuery(name);
   } else {
     databaseQuery = xrService.getORSession().getQuery(name);
   }
 }
  /** Override the constructor for Aggregate system to allow us to read and write XML */
  public CMWorkbenchIntegrationSystem() {
    super();

    ClassDescriptor descriptor =
        (ClassDescriptor) project.getDescriptors().get(ConversionDataObject.class);
    addNamedQueries(descriptor.getQueryManager());

    buildProject();
  }
 public void testXmlPropertiesOnField() {
   ClassDescriptor descriptor = project.getClassDescriptor(Foo.class);
   DatabaseMapping mapping = descriptor.getMappingForAttributeName("bar2");
   Map<Object, Object> properties = mapping.getProperties();
   assertTrue("Incorrect number of properties", properties.size() == 1);
   Object property = properties.get(FIELD_PROPERTY_2_NAME);
   assertNotNull(property);
   assertTrue("Incorrect value for property", property.equals("bar2Value"));
 }
 public void setup() {
   super.setup();
   // add a join between BabyMonitor and Baby what will complete a loop when combined with the
   // superclass' joins
   ClassDescriptor descriptor = getSession().getClassDescriptor(BabyMonitor.class);
   oldJoinFetch = ((OneToOneMapping) descriptor.getMappingForAttributeName("baby")).getJoinFetch();
   ((OneToOneMapping) descriptor.getMappingForAttributeName("baby")).useInnerJoinFetch();
   descriptor.reInitializeJoinedAttributes();
 }
  protected ClassDescriptor buildAbstractDirectMappingDescriptor() {
    ClassDescriptor descriptor = super.buildAbstractDirectMappingDescriptor();

    XMLDirectMapping attributeClassificationNameMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("attributeClassification");
    attributeClassificationNameMapping.setGetMethodName("getAttributeClassificationName");
    attributeClassificationNameMapping.setSetMethodName("setAttributeClassificationName");

    return descriptor;
  }
  protected ClassDescriptor buildQueryArgumentDescriptor() {
    ClassDescriptor descriptor = super.buildQueryArgumentDescriptor();

    XMLDirectMapping referenceClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("type");
    referenceClassMapping.setGetMethodName("getTypeName");
    referenceClassMapping.setSetMethodName("setTypeName");

    return descriptor;
  }
  protected ClassDescriptor buildInterfaceContainerPolicyDescriptor() {
    ClassDescriptor descriptor = super.buildInterfaceContainerPolicyDescriptor();

    XMLDirectMapping referenceClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("containerClass");
    referenceClassMapping.setGetMethodName("getContainerClassName");
    referenceClassMapping.setSetMethodName("setContainerClassName");

    return descriptor;
  }
  protected ClassDescriptor buildInstantiationPolicyDescriptor() {
    ClassDescriptor descriptor = super.buildInstantiationPolicyDescriptor();

    XMLDirectMapping referenceClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("factoryClass");
    referenceClassMapping.setGetMethodName("getFactoryClassName");
    referenceClassMapping.setSetMethodName("setFactoryClassName");

    return descriptor;
  }
  protected ClassDescriptor buildInheritancePolicyDescriptor() {
    ClassDescriptor descriptor = super.buildInheritancePolicyDescriptor();

    XMLDirectMapping referenceClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("parentClass");
    referenceClassMapping.setGetMethodName("getParentClassName");
    referenceClassMapping.setSetMethodName("setParentClassName");

    return descriptor;
  }
  protected ClassDescriptor buildForeignReferenceMappingDescriptor() {
    ClassDescriptor descriptor = super.buildForeignReferenceMappingDescriptor();

    XMLDirectMapping referenceClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("referenceClass");
    referenceClassMapping.setGetMethodName("getReferenceClassName");
    referenceClassMapping.setSetMethodName("setReferenceClassName");

    return descriptor;
  }
  protected ClassDescriptor buildTransformerBasedFieldTransformationDescriptor() {
    ClassDescriptor descriptor = super.buildTransformerBasedFieldTransformationDescriptor();

    XMLDirectMapping objectClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("transformerClass");
    objectClassMapping.setGetMethodName("getTransformerClassName");
    objectClassMapping.setSetMethodName("setTransformerClassName");

    return descriptor;
  }
  protected ClassDescriptor buildMethodBaseQueryRedirectorDescriptor() {
    ClassDescriptor descriptor = super.buildMethodBaseQueryRedirectorDescriptor();

    XMLDirectMapping referenceClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("methodClass");
    referenceClassMapping.setGetMethodName("getMethodClassName");
    referenceClassMapping.setSetMethodName("setMethodClassName");

    return descriptor;
  }
  protected ClassDescriptor buildTypedAssociationDescriptor() {
    ClassDescriptor descriptor = super.buildTypedAssociationDescriptor();

    XMLDirectMapping keyMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("key");
    keyMapping.setAttributeClassification(null);
    keyMapping.setGetMethodName("getKey");
    keyMapping.setSetMethodName("setKey");

    return descriptor;
  }
 public void testForRedirectorsAndInterceptors() {
   ClassDescriptor descriptor = getServerSession(m_persistenceUnit).getDescriptor(Address.class);
   assertTrue(
       "CacheInterceptor was not set on decriptor",
       descriptor.getCacheInterceptorClassName() != null);
   assertTrue(
       "All queries default redirector was not set on decriptor",
       descriptor.getDefaultQueryRedirector() != null);
   assertTrue(
       "Read All queries default redirector was not set on decriptor",
       descriptor.getDefaultReadAllQueryRedirector() != null);
   assertTrue(
       "Read Object queries default redirector was not set on decriptor",
       descriptor.getDefaultReadObjectQueryRedirector() != null);
   assertTrue(
       "Report queries default redirector was not set on decriptor",
       descriptor.getDefaultReportQueryRedirector() != null);
   assertTrue(
       "Insert queries default redirector was not set on decriptor",
       descriptor.getDefaultInsertObjectQueryRedirector() != null);
   assertTrue(
       "Update queries default redirector was not set on decriptor",
       descriptor.getDefaultUpdateObjectQueryRedirector() != null);
   assertTrue(
       "Delete queries default redirector was not set on decriptor",
       descriptor.getDefaultDeleteObjectQueryRedirector() != null);
 }
 public void testClassProperties() {
   ClassDescriptor descriptor = project.getClassDescriptor(Foo.class);
   Map<Object, Object> properties = descriptor.getProperties();
   assertTrue("Incorrect number of properties", properties.size() == 2);
   Object property = properties.get(CLASS_PROPERTY_1_NAME);
   assertNotNull(property);
   assertTrue("Incorrect value for property", property.equals("value1"));
   property = properties.get(CLASS_PROPERTY_2_NAME);
   assertNotNull(property);
   assertTrue("Incorrect value for property", property.equals(new Integer("121")));
 }
  @Override
  protected ClassDescriptor buildPLSQLrecordDescriptor() {

    ClassDescriptor descriptor = super.buildPLSQLrecordDescriptor();
    XMLDirectMapping javaTypeMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("javaType");
    javaTypeMapping.setGetMethodName("getJavaTypeName");
    javaTypeMapping.setSetMethodName("setJavaTypeName");

    return descriptor;
  }
 private Object wrapEnumeration(Object object, Class enumerationClass) {
   Class generatedClass = this.getClassToGeneratedClasses().get(enumerationClass.getName());
   if (generatedClass != null && WrappedValue.class.isAssignableFrom(generatedClass)) {
     ClassDescriptor desc =
         xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
     Object newObject = desc.getInstantiationPolicy().buildNewInstance();
     ((WrappedValue) newObject).setValue(object);
     object = newObject;
   }
   return object;
 }
  @Override
  protected ClassDescriptor buildStoredProcedureArgumentDescriptor() {

    ClassDescriptor descriptor = super.buildStoredProcedureArgumentDescriptor();

    XMLDirectMapping argumentTypeMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("argumentType");
    argumentTypeMapping.setGetMethodName("getArgumentTypeName");
    argumentTypeMapping.setSetMethodName("setArgumentTypeName");

    return descriptor;
  }
  @Test
  public void testExtensionAttribute_eclipselink_data() {
    ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class);
    ClassDescriptor referenceDescriptor =
        jpaMetadataProvider.getClassDescriptor(TestDataObjectExtension.class);
    assertNotNull(
        "A classDescriptor should have been retrieved from JPA for TestDataObject",
        classDescriptor);
    assertNotNull(
        "A classDescriptor should have been retrieved from JPA for TestDataObjectExtension",
        referenceDescriptor);
    DatabaseMapping databaseMapping = classDescriptor.getMappingForAttributeName("extension");
    assertNotNull("extension mapping missing from metamodel", databaseMapping);
    assertTrue("Should be a OneToOne mapping", databaseMapping instanceof OneToOneMapping);
    OneToOneMapping mapping = (OneToOneMapping) databaseMapping;

    assertEquals(
        "Should be mapped by primaryKeyProperty", "primaryKeyProperty", mapping.getMappedBy());
    Map<DatabaseField, DatabaseField> databaseFields = mapping.getSourceToTargetKeyFields();
    assertEquals(1, databaseFields.size());
    for (DatabaseField sourceField : databaseFields.keySet()) {
      DatabaseField targetField = databaseFields.get(sourceField);
      assertEquals("PK_PROP", sourceField.getName());
      assertEquals("PK_PROP", targetField.getName());
    }

    assertNotNull(
        "Reference descriptor missing from relationship", mapping.getReferenceDescriptor());
    assertEquals(
        "Reference descriptor should be the one for TestDataObjectExtension",
        referenceDescriptor,
        mapping.getReferenceDescriptor());

    assertNotNull("selection query relationship missing", mapping.getSelectionQuery());
    assertNotNull("selection query missing name", mapping.getSelectionQuery().getName());
    assertEquals(
        "selection query name incorrect", "extension", mapping.getSelectionQuery().getName());
    assertNotNull(
        "selection query reference class", mapping.getSelectionQuery().getReferenceClass());
    assertEquals(
        "selection query reference class incorrect",
        TestDataObjectExtension.class,
        mapping.getSelectionQuery().getReferenceClass());
    assertNotNull(
        "selection query reference class name",
        mapping.getSelectionQuery().getReferenceClassName());
    assertNotNull(
        "selection query source mapping missing", mapping.getSelectionQuery().getSourceMapping());
    assertEquals(
        "selection query source mapping incorrect",
        mapping,
        mapping.getSelectionQuery().getSourceMapping());
  }
 protected int removeOptimisticLocking(Project project) {
   int removed = 0;
   Iterator descriptors = project.getDescriptors().values().iterator();
   while (descriptors.hasNext()) {
     ClassDescriptor desc = (ClassDescriptor) descriptors.next();
     if (desc.getOptimisticLockingPolicy() != null) {
       desc.setOptimisticLockingPolicy(null);
       removed++;
     }
   }
   return removed;
 }
 public void reset() {
   getAbstractSession().rollbackTransaction();
   getSession().getIdentityMapAccessor().initializeIdentityMaps();
   descriptor.getQueryManager().setReadObjectQuery(readObjectQuery);
   descriptor.getQueryManager().setReadAllQuery(readAllQuery);
   descriptor.getQueryManager().setDeleteQuery(deleteObjectQuery);
   descriptor.getQueryManager().setInsertQuery(insertQuery);
   descriptor.getQueryManager().setUpdateQuery(updateQuery);
   boolean redirectedReadObject = false;
   boolean redirectedReadAll = false;
   boolean redirectedDeleteObject = false;
   boolean redirectedInsert = false;
   boolean redirectedUpdate = false;
 }