Exemple #1
0
  public PersistenceQuery createCall(final String spCall, final Class[] types) {
    FieldDescriptor[] fields;
    String[] jdoFields0;
    String[] jdoFields;
    String sql;
    int[] sqlTypes0;
    int[] sqlTypes;
    int count;

    // changes for the SQL Direct interface begins here
    if (spCall.startsWith("SQL")) {
      sql = spCall.substring(4);

      if (LOG.isDebugEnabled()) {
        LOG.debug(Messages.format("jdo.directSQL", sql));
      }

      return new SQLQuery(this, _factory, sql, types, true);
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug(Messages.format("jdo.spCall", spCall));
    }

    fields = _clsDesc.getFields();
    jdoFields0 = new String[fields.length + 1];
    sqlTypes0 = new int[fields.length + 1];
    // the first field is the identity

    count = 1;
    jdoFields0[0] = _clsDesc.getIdentity().getFieldName();
    sqlTypes0[0] = ((JDOFieldDescriptor) _clsDesc.getIdentity()).getSQLType()[0];
    for (int i = 0; i < fields.length; ++i) {
      if (fields[i] instanceof JDOFieldDescriptor) {
        jdoFields0[count] = ((JDOFieldDescriptor) fields[i]).getSQLName()[0];
        sqlTypes0[count] = ((JDOFieldDescriptor) fields[i]).getSQLType()[0];
        ++count;
      }
    }
    jdoFields = new String[count];
    sqlTypes = new int[count];
    System.arraycopy(jdoFields0, 0, jdoFields, 0, count);
    System.arraycopy(sqlTypes0, 0, sqlTypes, 0, count);

    return ((BaseFactory) _factory)
        .getCallQuery(spCall, types, _clsDesc.getJavaClass(), jdoFields, sqlTypes);
  }
Exemple #2
0
    private Object followPath(Object parent) {
      // System.out.println("Following the path.");
      // follow the path
      JDOClassDescriptor curClassDesc = _classDescriptor;
      Object curObject = parent;
      for (int i = 1; i < _pathInfo.size(); i++) {
        String curFieldName = (String) _pathInfo.elementAt(i);
        try {
          JDOFieldDescriptor curFieldDesc = curClassDesc.getField(curFieldName);
          FieldHandler handler = curFieldDesc.getHandler();
          curObject = handler.getValue(curObject);
          curClassDesc = (JDOClassDescriptor) curFieldDesc.getClassDescriptor();
        } catch (Exception ex) {
          throw new NoSuchElementException(
              "An exception was thrown trying to access get methods to follow the path expression. "
                  + ex.toString());
        }
      }

      return curObject;
    }
Exemple #3
0
  public PersistenceQuery createQuery(
      final QueryExpression query, final Class[] types, final AccessMode accessMode)
      throws QueryException {
    AccessMode mode = (accessMode != null) ? accessMode : _clsDesc.getAccessMode();
    String sql = query.getStatement(mode == AccessMode.DbLocked);

    if (LOG.isDebugEnabled()) {
      LOG.debug(Messages.format("jdo.createSql", sql));
    }

    return new SQLQuery(this, _factory, sql, types, false);
  }
Exemple #4
0
  SQLEngine(
      final JDOClassDescriptor clsDesc, final PersistenceFactory factory, final String stampField)
      throws MappingException {

    _clsDesc = clsDesc;
    _factory = factory;
    _keyGen = null;

    if (_clsDesc.getExtends() == null) {
      KeyGeneratorDescriptor keyGenDesc = clsDesc.getKeyGeneratorDescriptor();
      if (keyGenDesc != null) {
        int[] tempType = ((JDOFieldDescriptor) _clsDesc.getIdentity()).getSQLType();
        _keyGen =
            keyGenDesc
                .getKeyGeneratorRegistry()
                .getKeyGenerator(_factory, keyGenDesc, (tempType == null) ? 0 : tempType[0]);

        // Does the key generator support the sql type specified in the mapping?
        _keyGen.supportsSqlType(tempType[0]);
      }
    }

    // construct field and id info
    Vector idsInfo = new Vector();
    Vector fieldsInfo = new Vector();

    /*
     * Implementation Note:
     * Extends and Depends has some special mutual exclusive
     * properties, which implementator should aware of.
     *
     * A Depended class may depends on another depended class
     * A class should either extends or depends on other class
     * A class should not depend on extending class.
     *  because, it is the same as depends on the base class
     * A class may be depended by zero or more classes
     * A class may be extended by zero or more classes
     * A class may extends only zero or one class
     * A class may depends only zero or one class
     * A class may depend on extended class
     * A class may extend a dependent class.
     * A class may extend a depended class.
     * No loop or circle should exist
     */
    // then, we put depended class ids in the back
    JDOClassDescriptor base = clsDesc;

    // walk until the base class which this class extends
    base = clsDesc;
    Stack stack = new Stack();
    stack.push(base);
    while (base.getExtends() != null) {
      // if (base.getDepends() != null) {
      //     throw new MappingException("Class should not both depends on and extended other
      // classes");
      // }
      base = (JDOClassDescriptor) base.getExtends();
      stack.push(base);
      // do we need to add loop detection?
    }

    // now base is either the base of extended class, or
    // clsDesc
    // we always put the original id info in front
    // [oleg] except for SQL name, it may differ.
    FieldDescriptor[] baseIdDescriptors = base.getIdentities();
    FieldDescriptor[] idDescriptors = clsDesc.getIdentities();

    for (int i = 0; i < baseIdDescriptors.length; i++) {
      if (baseIdDescriptors[i] instanceof JDOFieldDescriptor) {
        String name = baseIdDescriptors[i].getFieldName();
        String[] sqlName = ((JDOFieldDescriptor) baseIdDescriptors[i]).getSQLName();
        int[] sqlType = ((JDOFieldDescriptor) baseIdDescriptors[i]).getSQLType();
        FieldHandlerImpl fh = (FieldHandlerImpl) baseIdDescriptors[i].getHandler();

        // The extending class may have other SQL names for identity fields
        for (int j = 0; j < idDescriptors.length; j++) {
          if (name.equals(idDescriptors[j].getFieldName())
              && (idDescriptors[j] instanceof JDOFieldDescriptor)) {
            sqlName = ((JDOFieldDescriptor) idDescriptors[j]).getSQLName();
            break;
          }
        }
        idsInfo.add(
            new SQLColumnInfo(
                sqlName[0],
                sqlType[0],
                fh.getConvertTo(),
                fh.getConvertFrom(),
                fh.getConvertParam()));
      } else {
        throw new MappingException("Except JDOFieldDescriptor");
      }
    }

    // then do the fields
    while (!stack.empty()) {
      base = (JDOClassDescriptor) stack.pop();
      FieldDescriptor[] fieldDescriptors = base.getFields();
      for (int i = 0; i < fieldDescriptors.length; i++) {
        // fieldDescriptors[i] is persistent in db if it is not transient
        // and it is a JDOFieldDescriptor or has a ClassDescriptor
        if (!fieldDescriptors[i].isTransient()) {
          if ((fieldDescriptors[i] instanceof JDOFieldDescriptor)
              || (fieldDescriptors[i].getClassDescriptor() != null)) {

            fieldsInfo.add(
                new SQLFieldInfo(
                    clsDesc, fieldDescriptors[i], base.getTableName(), !stack.empty()));
          }
        }
      }
    }

    _ids = new SQLColumnInfo[idsInfo.size()];
    idsInfo.copyInto(_ids);

    _fields = new SQLFieldInfo[fieldsInfo.size()];
    fieldsInfo.copyInto(_fields);

    _loadStatement = new SQLStatementLoad(this, factory);
    _createStatement = new SQLStatementCreate(this, factory);
    _removeStatement = new SQLStatementRemove(this, factory);
    _storeStatement = new SQLStatementStore(this, factory, _loadStatement.getLoadStatement());
  }
Exemple #5
0
 public String toString() {
   return _clsDesc.toString();
 }