Package javax.persistence

Examples of javax.persistence.Id


        try{
            do {
                Field[] fields = varClass.getDeclaredFields();
                for (int i = 0; i < fields.length && idValue == null; i++) {
                    Field field = fields[i];
                    Id id = field.getAnnotation(Id.class);
                    if (id != null) {
                        try {
                            idValue = callIdMethod(o, "get"
                                    + Character.toUpperCase(field.getName().charAt(0))
                                    + field.getName().substring(1));
                        } catch (NoSuchMethodException e) {
                            idValue = (Serializable) field.get(o);
                        }
                    }
                }
            } while ((varClass = varClass.getSuperclass()) != null && idValue == null);
            if (idValue == null) {
                varClass = o.getClass();
                do {
                    Method[] methods = varClass.getMethods();
                    for (int i = 0; i < methods.length && idValue == null; i++) {
                        Method method = methods[i];
                        Id id = method.getAnnotation(Id.class);
                        if (id != null) {
                            idValue = (Serializable) method.invoke(o);
                        }
                    }
                } while ((varClass = varClass.getSuperclass()) != null && idValue == null);
View Full Code Here


        Class<? extends Object> varClass = o.getClass();
        do {
                Field[] fields = varClass.getDeclaredFields();
                for (int i = 0; i < fields.length; i++) {
                    Field field = fields[i];
                    Id id = field.getAnnotation(Id.class);
                    if (id != null) {
                       return true;
                    }
                }
        } while ((varClass = varClass.getSuperclass()) != null);
        varClass = o.getClass();
        do {
                    Method[] methods = varClass.getMethods();
                    for (int i = 0; i < methods.length; i++) {
                        Method method = methods[i];
                        Id id = method.getAnnotation(Id.class);
                        if (id != null) {
                            return true;
                        }
                    }
        } while ((varClass = varClass.getSuperclass()) != null );
View Full Code Here

    Serializable idValue = null;
    do {
      Field[] fields = varClass.getDeclaredFields();
      for (int i = 0; i < fields.length && idValue == null; i++) {
        Field field = fields[i];
        Id id = field.getAnnotation(Id.class);
        if (id != null) {
          try {
            idValue = callIdMethod(o, "get"
                + Character.toUpperCase(field.getName().charAt(0))
                + field.getName().substring(1));
          } catch (NoSuchMethodException e) {
            idValue = (Serializable) field.get(o);
          }
        }
      }
    } while ((varClass = varClass.getSuperclass()) != null && idValue == null);
    if (idValue == null) {
      varClass = o.getClass();
      do {
        Method[] methods = varClass.getMethods();
        for (int i = 0; i < methods.length && idValue == null; i++) {
          Method method = methods[i];
          Id id = method.getAnnotation(Id.class);
          if (id != null) {
            idValue = (Serializable) method.invoke(o);
          }
        }
      } while ((varClass = varClass.getSuperclass()) != null && idValue == null);
View Full Code Here

    }
    else {
      Column col = getAnnotation(objectType, parameterName, Column.class);
      if (col != null && ! isNullOrEmpty(col.name()))
        sn = col.name();
      Id id = getAnnotation(objectType, parameterName, Id.class);
      Version version = getAnnotation(objectType, parameterName, Version.class);
      GeneratedValue generated = getAnnotation(objectType, parameterName, GeneratedValue.class);
      Enumerated enumerated = getAnnotation(objectType, parameterName, Enumerated.class);
     
      boolean idFlag = id != null;
View Full Code Here

              colAnn = f.getAnnotation(Column.class);
              if (colAnn == null)
                continue;
            }

            Id idAnn = f.getAnnotation(Id.class);
            if (idAnn == null){
              idAnn = getter.getAnnotation(Id.class);
              if (idAnn == null)
                continue;
            }
View Full Code Here

          continue;
      }

      Property p = new Property();

      Id idAnn = getter.getAnnotation(Id.class);
      if (idAnn == null)
        idAnn = f.getAnnotation(Id.class);

      if (idAnn != null) {
        p.setAutoIncrement("1");
View Full Code Here

        p.setSize("");
      else if (Float.class.isAssignableFrom(f.getType())
          || float.class.isAssignableFrom(f.getType()))
        p.setSize("8");

      Id idAnn = getter.getAnnotation(Id.class);
      if (idAnn == null)
        idAnn = f.getAnnotation(Id.class);

      if (idAnn != null) {
        if (pList != null && hasIdProperty(pList))
View Full Code Here

            List<String> pkeyColumn = new ArrayList<>();
            List<Object> pkeyValue = new ArrayList<>();
            for (Field f : clazz.getDeclaredFields()) {
              // --------------------- PKey Field Handle ------------------------
              // check whether is primary key field
              Id id = f.getAnnotation(Id.class);
              if (id != null) {
                Column idCol = f.getAnnotation(Column.class);
                if (idCol != null && idCol.name() != null) {
                  pkeyColumn.add(idCol.name());
                  // check modifier if private set accessible
                  if (f.getModifiers() != Modifier.PUBLIC) {
                    f.setAccessible(true);
                  }
                  pkeyValue.add(f.get(temp));
                  isPkeyFound = true;
                  // adding ID column to ID holder(
                  if (HpUfisAppConstants.CON_ID.equals(idCol.name())) {
                    idValue = (f.get(temp) == null ? "" : f.get(temp).toString());
                  }
                 
                  // adding id_flight to id_flight holder
                  if (HpUfisAppConstants.CON_AFTTAB.equals(tabName)){
                    flightUrno = (f.get(temp) == null ? "" : f.get(temp).toString());
                    isFlightUrno = true;
                  }
                  continue;
                } else {
                  LOG.warn("Notification: Name of Column annotation is required for field={}", f.getName());
                }
              }
             
              // check whether is composite key field
              EmbeddedId cpzKey = f.getAnnotation(EmbeddedId.class);
              if (cpzKey != null) {
                Object cpzValue = f.get(temp);
                // get composite key columns
                Class<?> cpzClazz = f.getType();
                //LOG.debug("check 5");
                for (Field cpzField : cpzClazz.getDeclaredFields()) {
                  Column cpzCol = cpzField.getAnnotation(Column.class);
                  if (cpzCol != null && cpzCol.name() != null) {
                    pkeyColumn.add(cpzCol.name());
                    // check modifier if private set accessible
                    if (cpzField.getModifiers() != Modifier.PUBLIC) {
                      cpzField.setAccessible(true);
                    }          //  LOG.debug("check 7");
                    pkeyValue.add(cpzField.get(cpzValue));
                    //LOG.debug("check 8");                   
                    isPkeyFound = true;
                  } else {
                    LOG.warn("Notification: Name of Column annotation is required for field={}", cpzField.getName());
                  }
                }
                continue;
              }
              // --------------------- Non-PKey Field Handle ------------------------
              PropertyDescriptor pd = null;
              try {
                pd = new PropertyDescriptor(f.getName(), clazz);
              } catch (IntrospectionException e) {
                LOG.debug("No property found for field={}", f.getName());
                continue;
              }
              Method getterMethod = pd.getReadMethod();
 
              // According to command to build fields, odat, data
              // DRT: notify id only(DRT mark as deleted rec_status)
              // IRT: notify all
              // URT: notify all or change only
              Column col = f.getAnnotation(Column.class);
              if (col == null || col.name() == null) {
                LOG.warn("Column name not found in annotation for {} field={}", tabName, f.getName());
                continue;
              }
             
              // if idFlights empty or null, check id_flight from field to auto-fill
              if (header.getIdFlight().size() == 0) {
                // whether is flight urno(UAFT, URNO of AFTTAB, ID_FLIGHT)
                if (HpUfisAppConstants.CON_UAFT.equals(col.name())
                    || HpUfisAppConstants.CON_ID_FLIGHT.equals(col.name())) {
                  isFlightUrno =  true;
                }
              }
             
              Object tempOldValue = null;
              Object tempNewValue = null;
              switch (cmd) {
              case DRT:
                //tempNewValue = getterMethod.invoke(data);
                //fld.add(col.name().toUpperCase());
                //dat.add(tempOldValue);
                break;
              case IRT:
                if (data != null) {
                  tempNewValue = getterMethod.invoke(data);
                  fld.add(col.name().toUpperCase());
                  dat.add(tempNewValue);
                  if (isFlightUrno && tempNewValue != null) {
                    flightUrno = tempNewValue.toString();
                    //LOG.debug("check 12");
                    }
                } else {
                  LOG.warn("Data parameter is required for IRT notification");
                }
                break;
              case URT:
                if (data != null && oldData != null) {
                  tempNewValue = getterMethod.invoke(data);
                  tempOldValue = getterMethod.invoke(oldData);
                  String fldsConfig = HpCommonConfig.fields.get(tabName);
                  // flight urno
                  if (isFlightUrno && tempNewValue != null) {
                    flightUrno = tempNewValue.toString();
                  }
                  //LOG.debug("check 14");
                  if (HpUfisUtils.isNotEmptyStr(fldsConfig)) {
                    // check whether only send changed fields
                    if (fldsConfig.equals(HpUfisAppConstants.FLD_CHANGED)) {
                      if (tempNewValue != null && !tempNewValue.equals(tempOldValue)) {
                        fld.add(col.name().toUpperCase());
                        odat.add(tempOldValue);
                        dat.add(tempNewValue);
                      }
                    // check whether send all fields
                    } else if (fldsConfig.equals(HpUfisAppConstants.FLD_ALL)) {
                      fld.add(col.name().toUpperCase());
                      odat.add(tempOldValue);
                      dat.add(tempNewValue);
                    // check whether send selected fields only
                    } else if (fldsConfig.contains(col.name().toUpperCase())) {
                        fld.add(col.name().toUpperCase());
                        odat.add(tempOldValue);
                        dat.add(tempNewValue);
                    } else {
                      LOG.warn("Column={} is not contained in the notify fields list", col.name().toUpperCase());
                    }
                  } else {
                    LOG.warn("Notify Field Configuration cannot be null or empty");
                  }
                } else {
                  LOG.warn("Both old and new data are required for URT notification");
                }
                break;
              default:
                LOG.warn("Unsupported notification command: {}", cmd);
                break;
              }
              // Add id of the flight
              if (isFlightUrno && header.getIdFlight().size() == 0) {
                header.getIdFlight().add(flightUrno);
              }
            }
           
            LOG.debug("process fields, takes {}",System.currentTimeMillis()-startTime);
           
            // verify fld, data and old data size
            boolean isSizeMatched = true;
            if (UfisASCommands.IRT == cmd) {
              if (fld.size() != dat.size()) {
                isSizeMatched = false;
              }
            } else if (UfisASCommands.URT == cmd) {
              if (fld.size() != dat.size() || fld.size() != odat.size()) {
                isSizeMatched = false;
              }
            }
            if (isSizeMatched) {
              // exclusion check
              String exclusion = HpCommonConfig.exclusions.get(tabName);
              if ((UfisASCommands.DRT != cmd) && HpUfisUtils.isNotEmptyStr(exclusion)) {
                String[] excFields = exclusion.split(",");
                for (String s : excFields) {
                  int index = fld.indexOf(s.trim());
                  if (index != -1) {
                    fld.remove(index);
                    dat.remove(index);
                    if (UfisASCommands.URT == cmd) {
                      odat.remove(index);
                    }
                  }
                }
              }
              // check whether the ID column is defined in parent class
              if (!isPkeyFound) {
                Class<?> superClazz = clazz.getSuperclass();
                do {
                  for (Field f : superClazz.getDeclaredFields()) {
                    // check whether is primary key field
                    Id id = f.getAnnotation(Id.class);
                    if (id != null) {
                      Column idCol = f.getAnnotation(Column.class);
                      if (idCol != null && idCol.name() != null) {
                        pkeyColumn.add(idCol.name());
                        // check modifier if private set accessible
View Full Code Here

        try{
            do {
                Field[] fields = varClass.getDeclaredFields();
                for (int i = 0; i < fields.length && idValue == null; i++) {
                    Field field = fields[i];
                    Id id = field.getAnnotation(Id.class);
                    if (id != null) {
                        try {
                            idValue = callIdMethod(o, "get"
                                    + Character.toUpperCase(field.getName().charAt(0))
                                    + field.getName().substring(1));
                        } catch (NoSuchMethodException e) {
                            idValue = (Serializable) field.get(o);
                        }
                    }
                }
            } while ((varClass = varClass.getSuperclass()) != null && idValue == null);
            if (idValue == null) {
                varClass = o.getClass();
                do {
                    Method[] methods = varClass.getMethods();
                    for (int i = 0; i < methods.length && idValue == null; i++) {
                        Method method = methods[i];
                        Id id = method.getAnnotation(Id.class);
                        if (id != null) {
                            idValue = (Serializable) method.invoke(o);
                        }
                    }
                } while ((varClass = varClass.getSuperclass()) != null && idValue == null);
View Full Code Here

        Class<? extends Object> varClass = o.getClass();
        do {
                Field[] fields = varClass.getDeclaredFields();
                for (int i = 0; i < fields.length; i++) {
                    Field field = fields[i];
                    Id id = field.getAnnotation(Id.class);
                    if (id != null) {
                       return true;
                    }
                }
        } while ((varClass = varClass.getSuperclass()) != null);
        varClass = o.getClass();
        do {
                    Method[] methods = varClass.getMethods();
                    for (int i = 0; i < methods.length; i++) {
                        Method method = methods[i];
                        Id id = method.getAnnotation(Id.class);
                        if (id != null) {
                            return true;
                        }
                    }
        } while ((varClass = varClass.getSuperclass()) != null );
View Full Code Here

TOP

Related Classes of javax.persistence.Id

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.