Example #1
0
  private void loadCMPFields(JDBCEntityMetaData metadata) {
    // only non pk fields are stored here at first and then later
    // the pk fields are added to the front (makes sql easier to read)
    List<JDBCCMPFieldMetaData> cmpFieldsMD = metadata.getCMPFields();
    List<JDBCCMPFieldBridge> cmpFieldsList = new ArrayList<JDBCCMPFieldBridge>();
    // primary key cmp fields
    List<JDBCCMPFieldBridge> pkFieldsList = new ArrayList<JDBCCMPFieldBridge>();

    // create pk fields
    for (JDBCCMPFieldMetaData fieldMD : cmpFieldsMD) {
      if (fieldMD.isPrimaryKeyMember()) {
        pkFieldsList.add(createCMPField(metadata, fieldMD));
      }
    }
    for (JDBCCMPFieldMetaData fieldMD : cmpFieldsMD) {
      if (!fieldMD.isPrimaryKeyMember()) {
        cmpFieldsList.add(createCMPField(metadata, fieldMD));
      }
    }

    // save the pk fields in the pk field array
    primaryKeyFields = pkFieldsList.toArray(new JDBCCMPFieldBridge[pkFieldsList.size()]);
    // add the pk fields to the front of the cmp list, per guarantee above
    cmpFields = cmpFieldsList.toArray(new JDBCCMPFieldBridge[cmpFieldsList.size()]);
  }
  public JDBCCMPFieldBridge2(
      JDBCStoreManager2 manager,
      JDBCEntityBridge2 entity,
      JDBCCMPFieldMetaData metadata,
      int rowIndex) {
    this.rowIndex = rowIndex;
    this.entity = entity;
    jdbcType = manager.getJDBCTypeFactory().getJDBCType(metadata);
    pkClass = metadata.getEntity().getPrimaryKeyClass();
    pkField = metadata.getPrimaryKeyField();
    isPrimaryKeyMember = metadata.isPrimaryKeyMember();
    fieldName = metadata.getFieldName();
    fieldType = metadata.getFieldType();
    cmpFieldIAmMappedTo = null;
    columnName = metadata.getColumnName();

    log =
        Logger.getLogger(
            this.getClass().getName() + "." + entity.getEntityName() + "#" + getFieldName());
  }
Example #3
0
  public void init() throws Exception {
    dataSource = manager.getDataSource(metadata.getDataSourceName());
    qualifiedTableName = SQLUtil.fixTableName(metadata.getDefaultTableName(), dataSource);
    int dotIndex = qualifiedTableName.indexOf('.');
    tableName = dotIndex == -1 ? qualifiedTableName : qualifiedTableName.substring(dotIndex + 1);

    // CMP fields
    loadCMPFields(metadata);

    // CMR fields
    loadCMRFields(metadata);

    // create locking field
    JDBCOptimisticLockingMetaData lockMetaData = metadata.getOptimisticLocking();
    if (lockMetaData != null && lockMetaData.getLockingField() != null) {
      JDBCOptimisticLockingMetaData.LockingStrategy strategy = lockMetaData.getLockingStrategy();
      JDBCCMPFieldMetaData versionMD = lockMetaData.getLockingField();

      versionField = getCMPFieldByName(versionMD.getFieldName());
      boolean hidden = versionField == null;
      switch (strategy) {
        case VERSION_COLUMN_STRATEGY:
          {
            if (hidden) versionField = new JDBCLongVersionFieldBridge(manager, versionMD);
            else versionField = new JDBCLongVersionFieldBridge((JDBCCMP2xFieldBridge) versionField);
            break;
          }
        case TIMESTAMP_COLUMN_STRATEGY:
          {
            if (hidden) versionField = new JDBCTimestampVersionFieldBridge(manager, versionMD);
            else
              versionField =
                  new JDBCTimestampVersionFieldBridge((JDBCCMP2xFieldBridge) versionField);
            break;
          }
        case KEYGENERATOR_COLUMN_STRATEGY:
          {
            if (hidden)
              versionField =
                  new JDBCKeyGenVersionFieldBridge(
                      manager, versionMD, lockMetaData.getKeyGeneratorFactory());
            else
              versionField =
                  new JDBCKeyGenVersionFieldBridge(
                      (JDBCCMP2xFieldBridge) versionField, lockMetaData.getKeyGeneratorFactory());
            break;
          }
      }
      if (hidden) addCMPField(versionField);
      else tableFields[versionField.getTableIndex()] = versionField;
    }

    // audit fields
    JDBCAuditMetaData auditMetaData = metadata.getAudit();
    if (auditMetaData != null) {
      JDBCCMPFieldMetaData auditField = auditMetaData.getCreatedPrincipalField();
      if (auditField != null) {
        createdPrincipalField = getCMPFieldByName(auditField.getFieldName());
        if (createdPrincipalField == null) {
          createdPrincipalField = new JDBCCMP2xFieldBridge(manager, auditField);
          addCMPField(createdPrincipalField);
        }
      } else {
        createdPrincipalField = null;
      }

      auditField = auditMetaData.getCreatedTimeField();
      if (auditField != null) {
        createdTimeField = getCMPFieldByName(auditField.getFieldName());
        if (createdTimeField == null) {
          createdTimeField =
              new JDBCCMP2xFieldBridge(manager, auditField, JDBCTypeFactory.EQUALS, false);
          addCMPField(createdTimeField);
        } else {
          // just to override state factory and check-dirty-after-get
          createdTimeField =
              new JDBCCMP2xFieldBridge(
                  (JDBCCMP2xFieldBridge) createdTimeField, JDBCTypeFactory.EQUALS, false);
          tableFields[createdTimeField.getTableIndex()] = createdTimeField;
        }
      } else {
        createdTimeField = null;
      }

      auditField = auditMetaData.getUpdatedPrincipalField();
      if (auditField != null) {
        updatedPrincipalField = getCMPFieldByName(auditField.getFieldName());
        if (updatedPrincipalField == null) {
          updatedPrincipalField = new JDBCCMP2xUpdatedPrincipalFieldBridge(manager, auditField);
          addCMPField(updatedPrincipalField);
        } else {
          updatedPrincipalField =
              new JDBCCMP2xUpdatedPrincipalFieldBridge(
                  (JDBCCMP2xFieldBridge) updatedPrincipalField);
          tableFields[updatedPrincipalField.getTableIndex()] = updatedPrincipalField;
        }
      } else {
        updatedPrincipalField = null;
      }

      auditField = auditMetaData.getUpdatedTimeField();
      if (auditField != null) {
        updatedTimeField = getCMPFieldByName(auditField.getFieldName());
        if (updatedTimeField == null) {
          updatedTimeField = new JDBCCMP2xUpdatedTimeFieldBridge(manager, auditField);
          addCMPField(updatedTimeField);
        } else {
          updatedTimeField =
              new JDBCCMP2xUpdatedTimeFieldBridge((JDBCCMP2xFieldBridge) updatedTimeField);
          tableFields[updatedTimeField.getTableIndex()] = updatedTimeField;
        }
      } else {
        updatedTimeField = null;
      }
    }

    // ejbSelect methods
    loadSelectors(metadata);
  }
 /** This constructor creates a foreign key field. */
 public JDBCCMP2xFieldBridge(
     JDBCStoreManager manager, JDBCCMPFieldMetaData metadata, JDBCType jdbcType) {
   super(manager, metadata, jdbcType);
   cmpFieldIAmMappedTo = null;
   columnName = metadata.getColumnName();
 }