/**
   * Loads a class (do not initialize) from an attribute of {@link ConfigurationElement}
   *
   * @param confElm the configuration element
   * @param name the attribute name
   * @return the Class
   * @throws NoSuchMethodException if an error occurs
   * @throws SecurityException if an error occurs
   * @throws InvocationTargetException if an error occurs
   * @throws IllegalAccessException if an error occurs
   * @throws InstantiationException if an error occurs
   * @throws IllegalArgumentException if an error occurs
   */
  public Object createExecutableExtension(
      ConfigurationElement confElm, String name, Class[] argsClass, Object[] args)
      throws ClassNotFoundException, SecurityException, NoSuchMethodException,
          IllegalArgumentException, InstantiationException, IllegalAccessException,
          InvocationTargetException {
    String symbolicName = confElm.getExtension().getPlugin().getSymbolicName();
    String attribute = confElm.getAttribute(name);
    org.osgi.framework.Bundle osgiBundle = getOsgiBundle(symbolicName);
    Class cls = osgiBundle.loadClass(attribute);
    Constructor constructor = cls.getConstructor(argsClass);

    try {
      return constructor.newInstance(args);
    } catch (InstantiationException e1) {
      NucleusLogger.GENERAL.error(e1.getMessage(), e1);
      throw e1;
    } catch (IllegalAccessException e2) {
      NucleusLogger.GENERAL.error(e2.getMessage(), e2);
      throw e2;
    } catch (IllegalArgumentException e3) {
      NucleusLogger.GENERAL.error(e3.getMessage(), e3);
      throw e3;
    } catch (InvocationTargetException e4) {
      NucleusLogger.GENERAL.error(e4.getMessage(), e4);
      throw e4;
    }
  }
  public void registerExtensions() {
    if (extensionPoints.length > 0) {
      return;
    }
    List registeringExtensions = new ArrayList();

    BundleContext ctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();

    // parse the plugin files
    DocumentBuilder docBuilder = OSGiBundleParser.getDocumentBuilder();
    org.osgi.framework.Bundle[] osgiBundles = ctx.getBundles();
    for (org.osgi.framework.Bundle osgiBundle : osgiBundles) {
      URL pluginURL = osgiBundle.getEntry("plugin.xml");

      if (pluginURL == null) {
        continue;
      }

      Bundle bundle = registerBundle(osgiBundle);
      if (bundle == null) {
        // No MANIFEST.MF for this plugin.xml so ignore it
        continue;
      }

      List[] elements =
          OSGiBundleParser.parsePluginElements(docBuilder, this, pluginURL, bundle, osgiBundle);
      registerExtensionPointsForPluginInternal(elements[0], false);
      registeringExtensions.addAll(elements[1]);
    }
    extensionPoints =
        extensionPointsByUniqueId
            .values()
            .toArray(new ExtensionPoint[extensionPointsByUniqueId.values().size()]);

    // Register the extensions now that we have the extension-points all loaded
    for (int i = 0; i < registeringExtensions.size(); i++) {
      Extension extension = (Extension) registeringExtensions.get(i);
      ExtensionPoint exPoint = getExtensionPoint(extension.getExtensionPointId());
      if (exPoint == null) {
        if (extension.getPlugin() != null
            && extension.getPlugin().getSymbolicName() != null
            && extension.getPlugin().getSymbolicName().startsWith(DATANUCLEUS_PKG)) {
          NucleusLogger.GENERAL.warn(
              Localiser.msg(
                  "024002",
                  extension.getExtensionPointId(),
                  extension.getPlugin().getSymbolicName(),
                  extension.getPlugin().getManifestLocation()));
        }
      } else {
        extension.setExtensionPoint(exPoint);
        exPoint.addExtension(extension);
      }
    }
  }
  /**
   * Register the plugin bundle.
   *
   * @param osgiBundle the OSGi bundle
   * @return the Plugin
   */
  private Bundle registerBundle(org.osgi.framework.Bundle osgiBundle) {
    Bundle bundle = OSGiBundleParser.parseManifest(osgiBundle);
    if (bundle == null) {
      // Didn't parse correctly, so ignore it
      return null;
    }

    if (registeredPluginByPluginId.get(bundle.getSymbolicName()) == null) {
      if (NucleusLogger.GENERAL.isDebugEnabled()) {
        NucleusLogger.GENERAL.debug(
            "Registering bundle "
                + bundle.getSymbolicName()
                + " version "
                + bundle.getVersion()
                + " at URL "
                + bundle.getManifestLocation()
                + ".");
      }
      registeredPluginByPluginId.put(bundle.getSymbolicName(), bundle);
    }
    return bundle;
  }
Ejemplo n.º 4
0
 public void modificacion_ABM(EntityManager em) {
   EntityTransaction tx = em.getTransaction();
   try {
     tx.begin();
     if (id != 0) em.persist(this);
     tx.commit();
   } catch (Exception e) {
     NucleusLogger.GENERAL.error(">> Exception persisting data", e);
     System.err.println("Error persisting data : " + e.getMessage());
     return;
   } finally {
     if (tx.isActive()) tx.rollback();
   }
 }
  public void testOneToManyInterface() {
    Issue207Parent parent = new Issue207Parent("The parent");
    Issue207Child child = new Issue207Child("The child");
    parent.getChildren().add(child);
    child.setParent(parent);

    // Persist the objects
    beginTxn();
    NucleusLogger.GENERAL.info(">> inserting parent+child");
    pm.makePersistent(parent);
    commitTxn();
    pm.evictAll();

    // Check the results
  }
Ejemplo n.º 6
0
  /**
   * Initialisation method. This should be called AFTER using the populate method if you are going
   * to use populate. It creates the internal convenience arrays etc needed for normal operation.
   */
  public void initialise(ClassLoaderResolver clr, MetaDataManager mmgr) {
    if (hasExtension("field-name")) {
      // User has provided extension "field-name" meaning that we store the version in the column
      // for the specified field (like in JPA)
      String val = getValueForExtension("field-name");
      if (!StringUtils.isWhitespace(val)) {
        this.fieldName = val;
        this.columnName = null;
      }
    }

    if (fieldName == null) {
      // Cater for user specifying column name, or column
      if (columnMetaData == null && columnName != null) {
        columnMetaData = new ColumnMetaData();
        columnMetaData.setName(columnName);
        columnMetaData.parent = this;
      }

      // Interpret the "indexed" value to create our IndexMetaData where it wasn't specified that
      // way
      if (indexMetaData == null
          && columnMetaData != null
          && indexed != null
          && indexed != IndexedValue.FALSE) {
        indexMetaData = new IndexMetaData();
        indexMetaData.setUnique(indexed == IndexedValue.UNIQUE);
        indexMetaData.addColumn(columnMetaData.getName());
        indexMetaData.parent = this;
      }
    } else {
      if (getParent() instanceof AbstractClassMetaData) {
        AbstractMemberMetaData vermmd =
            ((AbstractClassMetaData) getParent()).getMetaDataForMember(fieldName);
        if (vermmd != null && java.util.Date.class.isAssignableFrom(vermmd.getType())) {
          NucleusLogger.GENERAL.debug(
              "Setting version-strategy of field "
                  + vermmd.getFullFieldName()
                  + " to DATE_TIME since is Date-based");
          versionStrategy = VersionStrategy.DATE_TIME;
        }
      }
    }
  }
  public int getSize(ObjectProvider ownerOP) {
    int numRows;

    String sizeStmt = getSizeStmt();
    try {
      ExecutionContext ec = ownerOP.getExecutionContext();
      ManagedConnection mconn = storeMgr.getConnection(ec);
      SQLController sqlControl = storeMgr.getSQLController();
      try {
        PreparedStatement ps = sqlControl.getStatementForQuery(mconn, sizeStmt);
        try {
          int jdbcPosition = 1;
          if (elementInfo == null) {
            jdbcPosition =
                BackingStoreHelper.populateOwnerInStatement(ownerOP, ec, ps, jdbcPosition, this);
          } else {
            if (usingJoinTable()) {
              jdbcPosition =
                  BackingStoreHelper.populateOwnerInStatement(ownerOP, ec, ps, jdbcPosition, this);
              if (elementInfo[0].getDiscriminatorMapping() != null) {
                jdbcPosition =
                    BackingStoreHelper.populateElementDiscriminatorInStatement(
                        ec, ps, jdbcPosition, true, elementInfo[0], clr);
              }
              if (relationDiscriminatorMapping != null) {
                jdbcPosition =
                    BackingStoreHelper.populateRelationDiscriminatorInStatement(
                        ec, ps, jdbcPosition, this);
              }
            } else {
              for (int i = 0; i < elementInfo.length; i++) {
                jdbcPosition =
                    BackingStoreHelper.populateOwnerInStatement(
                        ownerOP, ec, ps, jdbcPosition, this);
                if (elementInfo[i].getDiscriminatorMapping() != null) {
                  jdbcPosition =
                      BackingStoreHelper.populateElementDiscriminatorInStatement(
                          ec, ps, jdbcPosition, true, elementInfo[i], clr);
                }
                if (relationDiscriminatorMapping != null) {
                  jdbcPosition =
                      BackingStoreHelper.populateRelationDiscriminatorInStatement(
                          ec, ps, jdbcPosition, this);
                }
              }
            }
          }

          ResultSet rs = sqlControl.executeStatementQuery(ec, mconn, sizeStmt, ps);
          try {
            if (!rs.next()) {
              throw new NucleusDataStoreException(Localiser.msg("056007", sizeStmt));
            }

            numRows = rs.getInt(1);

            if (elementInfo != null && elementInfo.length > 1) {
              while (rs.next()) {
                numRows = numRows + rs.getInt(1);
              }
            }

            JDBCUtils.logWarnings(rs);
          } finally {
            rs.close();
          }
        } catch (SQLException sqle) {
          NucleusLogger.GENERAL.error("Exception in size", sqle);
          throw sqle;
        } finally {
          sqlControl.closeStatement(mconn, ps);
        }
      } finally {
        mconn.release();
      }
    } catch (SQLException e) {
      throw new NucleusDataStoreException(Localiser.msg("056007", sizeStmt), e);
    }

    return numRows;
  }