예제 #1
0
 @Override
 public int hashCode() {
   return super.hashCode()
       + relationship.hashCode()
       + ClassMetadata.hashCode(deleteAction)
       + ClassMetadata.hashCode(keyName)
       + ClassMetadata.hashCode(elementClassName)
       + ClassMetadata.hashCode(relatedEntity);
 }
예제 #2
0
 private void assertClassHandler() {
   int id1 = storeItem();
   int id2 = storeItem();
   int smallerID = Math.min(id1, id2);
   int biggerID = Math.max(id1, id2);
   ClassMetadata classMetadata = new ClassMetadata(container(), reflector().forClass(Item.class));
   assertHandlerComparison(
       (Comparable4) classMetadata.typeHandler(), new Integer(smallerID), new Integer(biggerID));
 }
예제 #3
0
 @Override
 public boolean equals(Object other) {
   if (other instanceof SecondaryKeyMetadata) {
     SecondaryKeyMetadata o = (SecondaryKeyMetadata) other;
     return super.equals(o)
         && relationship == o.relationship
         && ClassMetadata.nullOrEqual(deleteAction, o.deleteAction)
         && ClassMetadata.nullOrEqual(keyName, o.keyName)
         && ClassMetadata.nullOrEqual(elementClassName, o.elementClassName)
         && ClassMetadata.nullOrEqual(relatedEntity, o.relatedEntity);
   } else {
     return false;
   }
 }
예제 #4
0
  @Override
  public void resolve(MarkerList markers, IContext context) {
    super.resolve(markers, context);

    IClassBody body = this.theClass.getBody();
    if (body != null) {
      int count = body.methodCount();
      for (int i = 0; i < count; i++) {
        this.checkMethod(body.getMethod(i));
      }
    }

    if ((this.methods & APPLY) == 0) {
      Method m = new Method(this.theClass, Name.apply, this.theClass.getType());
      IParameter[] parameters = this.theClass.getParameters();
      int parameterCount = this.theClass.parameterCount();

      m.modifiers = Modifiers.PUBLIC | Modifiers.STATIC;
      m.setParameters(parameters, parameterCount);
      m.setTypeVariables(this.theClass.getTypeVariables(), this.theClass.genericCount());

      if (parameterCount > 0 && parameters[parameterCount - 1].isVarargs()) {
        m.setVarargs();
      }
      this.applyMethod = m;
    }
  }
예제 #5
0
 public final void writeNew(
     Transaction trans, Pointer4 pointer, ClassMetadata classMetadata, ByteArrayBuffer buffer) {
   writeEncrypt(buffer, pointer.address(), 0);
   if (classMetadata == null) {
     return;
   }
   classMetadata.addToIndex(trans, pointer.id());
 }
예제 #6
0
 private ClassMetadata singleClassConstraint() {
   if (requiresSort()) {
     return null;
   }
   QConClass clazzconstr = classConstraint();
   if (clazzconstr == null) {
     return null;
   }
   ClassMetadata clazz = clazzconstr._classMetadata;
   if (clazz == null) {
     return null;
   }
   if (clazzconstr.hasChildren() || clazz.isArray()) {
     return null;
   }
   return clazz;
 }
예제 #7
0
  public QueryResult classOnlyQuery(QQueryBase query, ClassMetadata clazz) {
    if (!clazz.hasClassIndex()) {
      return new IdListQueryResult(query.transaction());
    }

    final AbstractQueryResult queryResult = newQueryResult(query.transaction());
    queryResult.loadFromClassIndex(clazz);
    return queryResult;
  }
  public int marshalledLength(final ObjectContainerBase stream, final ClassMetadata clazz) {
    final IntByRef len =
        new IntByRef(
            stream.stringIO().shortLength(clazz.nameToWrite())
                + Const4.OBJECT_LENGTH
                + (Const4.INT_LENGTH * 2)
                + (Const4.ID_LENGTH));

    len.value += clazz.index().ownLength();

    clazz.forEachDeclaredAspect(
        new Procedure4() {
          public void apply(Object arg) {
            len.value += _family._field.marshalledLength(stream, (ClassAspect) arg);
          }
        });
    return len.value;
  }
예제 #9
0
  public final boolean delete4(
      Transaction transaction, ObjectReference ref, Object obj, int cascade, boolean userCall) {
    int id = ref.getID();
    StatefulBuffer reader = readStatefulBufferById(transaction, id);
    if (reader != null) {
      if (obj != null) {
        if ((!showInternalClasses()) && Const4.CLASS_INTERNAL.isAssignableFrom(obj.getClass())) {
          return false;
        }
      }
      reader.setCascadeDeletes(cascade);
      transaction.idSystem().notifySlotDeleted(id, SlotChangeFactory.USER_OBJECTS);
      ClassMetadata classMetadata = ref.classMetadata();
      classMetadata.delete(reader, obj);

      return true;
    }
    return false;
  }
예제 #10
0
  public void write(
      final Transaction trans, final ClassMetadata clazz, final ByteArrayBuffer writer) {

    writer.writeShortString(trans, clazz.nameToWrite());

    int intFormerlyKnownAsMetaClassID = 0;
    writer.writeInt(intFormerlyKnownAsMetaClassID);

    writer.writeIDOf(trans, clazz.i_ancestor);

    writeIndex(trans, clazz, writer);

    writer.writeInt(clazz.declaredAspectCount());
    clazz.forEachDeclaredAspect(
        new Procedure4() {
          public void apply(Object arg) {
            _family._field.write(trans, clazz, (ClassAspect) arg, writer);
          }
        });
  }
예제 #11
0
 public long[] getIDsForClass(Transaction trans, ClassMetadata clazz) {
   final IntArrayList ids = new IntArrayList();
   clazz
       .index()
       .traverseIds(
           trans,
           new Visitor4() {
             public void visit(Object obj) {
               ids.add(((Integer) obj).intValue());
             }
           });
   return ids.asLong();
 }
예제 #12
0
  // Our QConPath objects are just placeholders to fields,
  // so the parents are reachable.
  // If we find a "real" constraint, we throw the QPath
  // out and replace it with the other constraint.
  private void morph(BooleanByRef removeExisting, QCon newConstraint, ReflectClass claxx) {
    boolean mayMorph = true;
    if (claxx != null) {
      ClassMetadata yc = i_trans.container().produceClassMetadata(claxx);
      if (yc != null) {
        Iterator4 i = iterateChildren();
        while (i.moveNext()) {
          QField qf = ((QCon) i.current()).getField();
          if (!yc.hasField(i_trans.container(), qf.name())) {
            mayMorph = false;
            break;
          }
        }
      }
    }

    if (mayMorph) {
      Iterator4 j = iterateChildren();
      while (j.moveNext()) {
        newConstraint.addConstraint((QCon) j.current());
      }
      if (hasJoins()) {
        Iterator4 k = iterateJoins();
        while (k.moveNext()) {
          QConJoin qcj = (QConJoin) k.current();
          qcj.exchangeConstraint(this, newConstraint);
          newConstraint.addJoin(qcj);
        }
      }
      i_parent.exchangeConstraint(this, newConstraint);
      removeExisting.value = true;

    } else {
      i_parent.addConstraint(newConstraint);
    }
  }
예제 #13
0
 private Constraint addInterfaceConstraint(ReflectClass claxx) {
   Collection4 classes = stream().classCollection().forInterface(claxx);
   if (classes.size() == 0) {
     QConClass qcc = new QConClass(_trans, null, null, claxx);
     addConstraint(qcc);
     return qcc;
   }
   Iterator4 i = classes.iterator();
   Constraint constr = null;
   while (i.moveNext()) {
     ClassMetadata classMetadata = (ClassMetadata) i.current();
     ReflectClass classMetadataClaxx = classMetadata.classReflector();
     if (classMetadataClaxx != null) {
       if (!classMetadataClaxx.isInterface()) {
         if (constr == null) {
           constr = constrain(classMetadataClaxx);
         } else {
           constr = constr.or(constrain(classMetadata.classReflector()));
         }
       }
     }
   }
   return constr;
 }
예제 #14
0
  public void defrag(
      final ClassMetadata classMetadata,
      final LatinStringIO sio,
      final DefragmentContextImpl context,
      int classIndexID) {
    readName(sio, context.sourceBuffer());
    readName(sio, context.targetBuffer());

    int metaClassID = 0;
    context.writeInt(metaClassID);

    // ancestor ID
    context.copyID();

    context.writeInt(indexIDForWriting(classIndexID));

    final int aspectCount = context.readInt();

    if (aspectCount > classMetadata.declaredAspectCount()) {
      throw new IllegalStateException();
    }

    final IntByRef processedAspectCount = new IntByRef(0);

    classMetadata.forEachDeclaredAspect(
        new Procedure4() {
          public void apply(Object arg) {
            if (processedAspectCount.value >= aspectCount) {
              return;
            }
            ClassAspect aspect = (ClassAspect) arg;
            _family._field.defrag(classMetadata, aspect, sio, context);
            processedAspectCount.value++;
          }
        });
  }
예제 #15
0
 protected void readIndex(
     ObjectContainerBase stream, ClassMetadata clazz, ByteArrayBuffer reader) {
   int indexID = reader.readInt();
   if (!stream.maintainsIndices() || !(stream instanceof LocalObjectContainer)) {
     return;
   }
   if (btree(clazz) != null) {
     return;
   }
   clazz.index().read(stream, validIndexId(indexID));
   if (isOldClassIndex(indexID)) {
     new ClassIndexesToBTrees_5_5().convert((LocalObjectContainer) stream, indexID, btree(clazz));
     stream.setDirtyInSystemTransaction(clazz);
   }
 }
예제 #16
0
  public final void read(ObjectContainerBase stream, ClassMetadata clazz, ByteArrayBuffer reader) {
    clazz.setAncestor(stream.classMetadataForId(reader.readInt()));

    if (clazz.callConstructor()) {
      // The logic further down checks the ancestor YapClass, whether
      // or not it is allowed, not to call constructors. The ancestor
      // YapClass may possibly have not been loaded yet.
      clazz.createConstructor(stream, clazz.classReflector(), clazz.getName(), true);
    }

    clazz.checkType();

    readIndex(stream, clazz, reader);

    clazz._aspects = createFields(clazz, reader.readInt());
    readFields(stream, reader, clazz._aspects);
  }
예제 #17
0
 public int instanceCount(ClassMetadata clazz, Transaction trans) {
   synchronized (lock()) {
     return clazz.indexEntryCount(trans);
   }
 }
예제 #18
0
 protected void writeIndex(Transaction trans, ClassMetadata clazz, ByteArrayBuffer writer) {
   int indexID = clazz.index().write(trans);
   writer.writeInt(indexIDForWriting(indexID));
 }
예제 #19
0
 protected int classMetadataID() {
   return _classMetadata.getID();
 }
예제 #20
0
  @Override
  public void write(ClassWriter writer, IValue instanceFields) throws BytecodeException {
    super.write(writer, instanceFields);
    MethodWriter mw;

    if ((this.methods & APPLY) == 0) {
      mw =
          new MethodWriterImpl(
              writer,
              writer.visitMethod(
                  this.applyMethod.getModifiers(),
                  "apply",
                  this.applyMethod.getDescriptor(),
                  this.applyMethod.getSignature(),
                  null));
      mw.begin();
      mw.writeTypeInsn(Opcodes.NEW, this.theClass.getType().getInternalName());
      mw.writeInsn(Opcodes.DUP);
      int len = this.theClass.parameterCount();
      for (int i = 0; i < len; i++) {
        IParameter param = this.theClass.getParameter(i);
        param.write(mw);
        mw.writeVarInsn(param.getType().getLoadOpcode(), i);
      }
      this.constructor.writeInvoke(mw, 0);
      mw.writeInsn(Opcodes.ARETURN);
      mw.end(this.theClass.getType());
    }

    String internal = this.theClass.getInternalName();
    if ((this.methods & EQUALS) == 0) {
      mw =
          new MethodWriterImpl(
              writer,
              writer.visitMethod(
                  Modifiers.PUBLIC | Modifiers.SYNTHETIC,
                  "equals",
                  "(Ljava/lang/Object;)Z",
                  null,
                  null));
      mw.setThisType(internal);
      mw.registerParameter(1, "obj", Types.OBJECT, 0);
      mw.begin();
      CaseClasses.writeEquals(mw, this.theClass);
      mw.end();
    }

    if ((this.methods & HASHCODE) == 0) {
      mw =
          new MethodWriterImpl(
              writer,
              writer.visitMethod(
                  Modifiers.PUBLIC | Modifiers.SYNTHETIC, "hashCode", "()I", null, null));
      mw.setThisType(internal);
      mw.begin();
      CaseClasses.writeHashCode(mw, this.theClass);
      mw.end();
    }

    if ((this.methods & TOSTRING) == 0) {
      mw =
          new MethodWriterImpl(
              writer,
              writer.visitMethod(
                  Modifiers.PUBLIC | Modifiers.SYNTHETIC,
                  "toString",
                  "()Ljava/lang/String;",
                  null,
                  null));
      mw.setThisType(internal);
      mw.begin();
      CaseClasses.writeToString(mw, this.theClass);
      mw.end();
    }
  }
  /**
   * query='dbConn.((0 as i close by (i + 100 where i <= max(Trener.getPremia())) as i join
   * count((Trener where getPremia() >= i and getPremia() < i + 100)) as c).(c + " Trenerow uzyskuje
   * premie pomiedzy " + i + " i " + i + 100) as message)' '
   */
  public java.util.List<java.lang.String> executeQuery(
      final ObjectContainerBase ocb, final Transaction t) {
    final LocalTransaction transLocal = (LocalTransaction) t;
    java.lang.Integer _asResult_i = 0;
    java.util.List<java.lang.Integer> _closeByResult = new ArrayList<java.lang.Integer>();
    _closeByResult.add(_asResult_i);

    int _i3 = 0;

    while (_i3 < _closeByResult.size()) {
      java.lang.Integer _closeByEl = _closeByResult.get(_i3);

      if (_closeByEl != null) {
        ocb.activate(_closeByEl, 1);
      }

      java.lang.Integer _ident_i = _closeByEl;
      java.lang.Integer _plusResult = _ident_i + 100;

      if (_plusResult != null) {
        ocb.activate(_plusResult, 2);
      }

      java.lang.Integer _whereEl = _plusResult;
      java.lang.Integer _ident_i1 = _closeByEl;
      final java.util.Collection<pl.wcislo.sbql4j.javac.test.football.model.Trener> _ident_Trener =
          new java.util.ArrayList<pl.wcislo.sbql4j.javac.test.football.model.Trener>();
      ClassMetadata _classMeta31 =
          ocb.classCollection()
              .getClassMetadata("pl.wcislo.sbql4j.javac.test.football.model.Trener");
      long[] _ids31 = _classMeta31.getIDs(transLocal);

      for (long _id31 : _ids31) {
        LazyObjectReference _ref31 = transLocal.lazyReferenceFor((int) _id31);
        _ident_Trener.add((pl.wcislo.sbql4j.javac.test.football.model.Trener) _ref31.getObject());
      }

      java.util.Collection<java.lang.Integer> _dotResult =
          new java.util.ArrayList<java.lang.Integer>();
      int _dotIndex = 0;

      if (_ident_Trener != null) {
        for (pl.wcislo.sbql4j.javac.test.football.model.Trener _dotEl : _ident_Trener) {
          if (_dotEl == null) {
            continue;
          }

          if (_dotEl != null) {
            ocb.activate(_dotEl, 1);
          }

          java.lang.Integer _mth_getPremiaResult = _dotEl.getPremia();

          if (_mth_getPremiaResult != null) {
            ocb.activate(_mth_getPremiaResult, 1);
          }

          if (_mth_getPremiaResult != null) {
            ocb.activate(_mth_getPremiaResult, 1);
          }

          _dotResult.add(_mth_getPremiaResult);
          _dotIndex++;
        }
      }

      Number _max7 = null;

      for (Number _maxEl7 : _dotResult) {
        _max7 = MathUtils.max(_max7, _maxEl7);
      }

      java.lang.Integer _maxResult = (java.lang.Integer) _max7;

      Boolean _less_or_equalResult = _ident_i1 <= _maxResult;
      java.lang.Integer _whereResult = null;

      if (_less_or_equalResult) {
        _whereResult = _plusResult;
      }

      java.lang.Integer _asResult_i1 = _whereResult;

      if (_asResult_i1 != null) {
        _closeByResult.add(_asResult_i1);
      }

      _i3++;
    }

    java.util.List<pl.wcislo.sbql4j.java.model.runtime.Struct> _joinResult =
        new java.util.ArrayList<pl.wcislo.sbql4j.java.model.runtime.Struct>();
    int _joinIndex = 0;

    for (java.lang.Integer _joinEl : _closeByResult) {
      if (_joinEl != null) {
        ocb.activate(_joinEl, 1);
      }

      final java.util.Collection<pl.wcislo.sbql4j.javac.test.football.model.Trener> _ident_Trener1 =
          new java.util.ArrayList<pl.wcislo.sbql4j.javac.test.football.model.Trener>();
      ClassMetadata _classMeta32 =
          ocb.classCollection()
              .getClassMetadata("pl.wcislo.sbql4j.javac.test.football.model.Trener");
      long[] _ids32 = _classMeta32.getIDs(transLocal);

      for (long _id32 : _ids32) {
        LazyObjectReference _ref32 = transLocal.lazyReferenceFor((int) _id32);
        _ident_Trener1.add((pl.wcislo.sbql4j.javac.test.football.model.Trener) _ref32.getObject());
      }

      java.util.Collection<pl.wcislo.sbql4j.javac.test.football.model.Trener> _whereResult1 =
          new java.util.ArrayList<pl.wcislo.sbql4j.javac.test.football.model.Trener>();
      int _whereLoopIndex1 = 0;

      for (pl.wcislo.sbql4j.javac.test.football.model.Trener _whereEl1 : _ident_Trener1) {
        if (_whereEl1 == null) {
          continue;
        }

        if (_whereEl1 != null) {
          ocb.activate(_whereEl1, 1);
        }

        java.lang.Integer _mth_getPremiaResult1 = _whereEl1.getPremia();

        if (_mth_getPremiaResult1 != null) {
          ocb.activate(_mth_getPremiaResult1, 1);
        }

        java.lang.Integer _ident_i2 = _joinEl;

        if (_ident_i2 != null) {
          ocb.activate(_ident_i2, 1);
        }

        Boolean _more_or_equalResult = _mth_getPremiaResult1 >= _ident_i2;
        java.lang.Boolean _andResult;

        if (!_more_or_equalResult) {
          _andResult = false;
        } else {
          java.lang.Integer _mth_getPremiaResult2 = _whereEl1.getPremia();

          if (_mth_getPremiaResult2 != null) {
            ocb.activate(_mth_getPremiaResult2, 1);
          }

          java.lang.Integer _ident_i3 = _joinEl;

          if (_ident_i3 != null) {
            ocb.activate(_ident_i3, 1);
          }

          java.lang.Integer _plusResult1 = _ident_i3 + 100;

          Boolean _lessResult = _mth_getPremiaResult2 < _plusResult1;
          _andResult = _lessResult;
        }

        if (_andResult) {
          _whereResult1.add(_whereEl1);
        }

        _whereLoopIndex1++;
      }

      java.lang.Integer _countResult = _whereResult1.size();
      java.lang.Integer _asResult_c = _countResult;
      _joinResult.add(OperatorUtils.cartesianProductSS(_joinEl, _asResult_c, "i", "c"));
      _joinIndex++;
    }

    java.util.List<java.lang.String> _dotResult1 = new java.util.ArrayList<java.lang.String>();
    int _dotIndex1 = 0;

    if (_joinResult != null) {
      for (pl.wcislo.sbql4j.java.model.runtime.Struct _dotEl1 : _joinResult) {
        if (_dotEl1 == null) {
          continue;
        }

        if (_dotEl1 != null) {
          ocb.activate(_dotEl1, 1);
        }

        java.lang.Integer _ident_c = (java.lang.Integer) _dotEl1.get("c");

        if (_ident_c != null) {
          ocb.activate(_ident_c, 1);
        }

        java.lang.String _plusResult2 = _ident_c + " Trenerow uzyskuje premie pomiedzy  ";
        java.lang.Integer _ident_i4 = (java.lang.Integer) _dotEl1.get("i");

        if (_ident_i4 != null) {
          ocb.activate(_ident_i4, 1);
        }

        java.lang.String _plusResult3 = _plusResult2 + _ident_i4;
        java.lang.String _plusResult4 = _plusResult3 + " i ";
        java.lang.Integer _ident_i5 = (java.lang.Integer) _dotEl1.get("i");

        if (_ident_i5 != null) {
          ocb.activate(_ident_i5, 1);
        }

        java.lang.Integer _plusResult5 = _ident_i5 + 100;
        java.lang.String _plusResult6 = _plusResult4 + _plusResult5;

        if (_plusResult6 != null) {
          ocb.activate(_plusResult6, 1);
        }

        _dotResult1.add(_plusResult6);
        _dotIndex1++;
      }
    }

    java.util.List<java.lang.String> _asResult_message = _dotResult1;
    pl.wcislo.sbql4j.db4o.utils.DerefUtils.activateResult(_asResult_message, ocb);

    return _asResult_message;
  }