Package org.eclipse.persistence.sessions

Examples of org.eclipse.persistence.sessions.Session


            return null;
         }
        if(".".equals(xPath)) {
           return (T) object;
        }
        Session session = this.getSession(object);
        XMLDescriptor xmlDescriptor = (XMLDescriptor) session.getDescriptor(object);
        StringTokenizer stringTokenizer = new StringTokenizer(xPath, "/");
        T value = getValueByXPath(object, xmlDescriptor.getObjectBuilder(), stringTokenizer, namespaceResolver, returnType);
        if(null == value) {
            DatabaseMapping selfMapping = xmlDescriptor.getObjectBuilder().getMappingForField(new XMLField("."));
            if(null != selfMapping) {
View Full Code Here


     * @param xPath The XPath statement
     * @param namespaceResolver A NamespaceResolver containing the prefix/URI pairings from the XPath statement.
     * @param value The value to be set.
     */
    public void setValueByXPath(Object object, String xPath, NamespaceResolver namespaceResolver, Object value) {
        Session session = this.getSession(object);
        XMLDescriptor xmlDescriptor = (XMLDescriptor) session.getDescriptor(object);
        StringTokenizer stringTokenizer = new StringTokenizer(xPath, "/");
        setValueByXPath(object, xmlDescriptor.getObjectBuilder(), stringTokenizer, namespaceResolver, value);
    }
View Full Code Here

     * @return
     *      An instance of the Java class mapped to the supplied XML type, or null
     *      if no result was found.
     */
    public <T> T createByXPath(Object parentObject, String xPath, NamespaceResolver namespaceResolver, Class<T> returnType) {
        Session session = this.getSession(parentObject);
        XMLDescriptor xmlDescriptor = (XMLDescriptor) session.getDescriptor(parentObject);
        StringTokenizer stringTokenizer = new StringTokenizer(xPath, "/");
        return createByXPath(parentObject, xmlDescriptor.getObjectBuilder(), stringTokenizer, namespaceResolver, returnType);
    }
View Full Code Here

   * @param query The JPQL query
   * @return the string of the JPQL query translated in SQL
   */
  private String rewriteEclipseLink(Query query) {
    EJBQueryImpl qi = (EJBQueryImpl) query;
    Session session = this.entityManager.unwrap(JpaEntityManager.class).getActiveSession();
    DatabaseQuery databaseQuery = (qi).getDatabaseQuery();
    databaseQuery.prepareCall(session, new DatabaseRecord());
    String sqlString = databaseQuery.getTranslatedSQLString(session,  new DatabaseRecord());
   
    //ADD THE ALIAS in the select statement (necessary for the temporary table construction.. ex for the worksheet)
View Full Code Here

   * those files in the order provided in the file.
   */
  public void generate() {
    String[] resourceSQLPropFileNames = getSQLInsertFileNames();
    if (resourceSQLPropFileNames.length > 0) { // If configuration is proper with at least one file
      Session session = ((EntityManagerImpl) entityManager).getActiveSession();
      ResourceBundle[] resourceBundleArr = new ResourceBundle[resourceSQLPropFileNames.length];
      entityManager.getTransaction().begin();

      for (int i = 0; i < resourceSQLPropFileNames.length; i++) { // For each Entity SQL property file,
        System.out.println("Reading from File - " + resourceSQLPropFileNames[i]);
        resourceBundleArr[i] = ResourceBundle.getBundle(resourceSQLPropFileNames[i]);// Get SQL statements as properties

        Set<String> keySet = resourceBundleArr[i].keySet();

        for (String string : keySet) {
          String currentSQL = (String) string;
          String sqlQuery = resourceBundleArr[i].getString(currentSQL);
          System.out.println("Executing Query - " + sqlQuery);
          SQLCall sqlCall = new SQLCall(sqlQuery);

          DataModifyQuery query = new DataModifyQuery();
          query.setCall(sqlCall);
          session.executeQuery(query);
        }
      }
      setMaterialInStore();
      entityManager.flush();
      entityManager.getTransaction().commit();
View Full Code Here

   */
  public void clean() {
    // Delete using SQLs
    String[] deleteStatements = getSQLDeleteStatements();
    if (deleteStatements.length > 0) { // If configuration is proper with at least one delete Statements
      Session session = ((EntityManagerImpl) entityManager).getActiveSession();
      entityManager.getTransaction().begin();
      for (String deleteStatement : deleteStatements) {
        System.out.println("Cleaning - " + deleteStatement);
        SQLCall sqlCall = new SQLCall(deleteStatement);

        DataModifyQuery query = new DataModifyQuery();
        query.setCall(sqlCall);
        session.executeQuery(query);
      }
      entityManager.getTransaction().commit();
    } else {
      System.err.println("Delete configuration file doesn't have any delete statements.");
    }
View Full Code Here

     *   primary key.
     */
    public <T> T find(Class<T> entityClass, Object primaryKey) {
        try {
            verifyOpen();
            Session session = getActiveSession();
            ClassDescriptor descriptor = session.getDescriptor(entityClass);
            if (descriptor == null || descriptor.isAggregateDescriptor() || descriptor.isAggregateCollectionDescriptor()) {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("unknown_bean_class", new Object[] { entityClass }));
            }
            return (T) findInternal(descriptor, session, primaryKey);
        } catch (RuntimeException e) {
View Full Code Here

     *   second argument is not a valid type for that entity's primaryKey.
     */
    public Object find(String entityName, Object primaryKey) {
        try {
            verifyOpen();
            Session session = getActiveSession();
            ClassDescriptor descriptor = session.getDescriptorForAlias(entityName);
            if (descriptor == null || descriptor.isAggregateDescriptor() || descriptor.isAggregateCollectionDescriptor()) {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("unknown_entitybean_name", new Object[] { entityName }));
            }
            return findInternal(descriptor, session, primaryKey);
        } catch (RuntimeException e) {
View Full Code Here

        if (queryHandler == null) {
            throw DBWSException.couldNotLocateQueryForSession(name,
                xrService.getORSession().getName());
        }
        queryHandler.initialize(xrService, this);
        Session oxSession = xrService.getOXSession();
        QName resultType = result == null ? null : result.getType();
        addSimpleXMLFormatModelDescriptor(xrService);
        addValueObjectDescriptor(xrService);
        if (resultType == null) {
            if (isAttachment()) {
                Attachment attachment = result.getAttachment();
                XMLDescriptor descriptor =
                    (XMLDescriptor)oxSession.getProject().getClassDescriptor(DataHandler.class);
                if (descriptor == null) {
                    descriptor = new XMLDescriptor();
                    descriptor.setAlias("DataHandler");
                    descriptor.setJavaClass(DataHandler.class);
                    descriptor.setInstantiationPolicy(
                        this.new DataHandlerInstantiationPolicy(attachment.getMimeType()));
                    XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
                    mapping.setAttributeName("results");
                    mapping.setAttributeAccessor(new AttributeAccessor() {
                        @Override
                        public Object getAttributeValueFromObject(Object object)
                            throws DescriptorException {
                            Object result = null;
                            DataHandler dataHandler = (DataHandler)object;
                            try {
                                result = dataHandler.getContent();
                                if (result instanceof InputStream) {
                                    InputStream is = (InputStream)result;
                                    byte[] buf = new byte[2048];
                                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                    int bytesRead = is.read(buf);
                                    while (bytesRead >= 0) {
                                        baos.write(buf, 0, bytesRead);
                                        bytesRead = is.read(buf);
                                    }
                                    result = baos.toByteArray();
                                }
                            }
                            catch (IOException e) {
                                // e.printStackTrace(); ignore
                            }
                            return result;
                        }
                        @Override
                        public void setAttributeValueInObject(Object object, Object value)
                            throws DescriptorException {
                            // TODO - figure out if inbound-path needs to be handled
                        }
                    });
                    mapping.setXPath(DEFAULT_SIMPLE_XML_FORMAT_TAG + "/" +
                        DEFAULT_SIMPLE_XML_TAG + "/attachment");
                    mapping.setSwaRef(true);
                    mapping.setShouldInlineBinaryData(false);
                    mapping.setMimeType(attachment.getMimeType());
                    descriptor.addMapping(mapping);
                    NamespaceResolver nr = new NamespaceResolver();
                    descriptor.setNamespaceResolver(nr);
                    oxSession.getProject().addDescriptor(descriptor);
                    ((DatabaseSessionImpl)oxSession)
                        .initializeDescriptorIfSessionAlive(descriptor);
                    xrService.getXMLContext().storeXMLDescriptorByQName(descriptor);
                }
            }
View Full Code Here

            }
        }
    }

    protected void addValueObjectDescriptor(XRServiceAdapter xrService) {
        Session oxSession = xrService.getOXSession();
        XMLDescriptor descriptor = (XMLDescriptor)oxSession.getProject().getClassDescriptor(
            ValueObject.class);
        if (descriptor == null) {
            descriptor = new XMLDescriptor();
            descriptor.setAlias("ValueObject");
            descriptor.setJavaClass(ValueObject.class);
            XMLDirectMapping mapping = new XMLDirectMapping();
            mapping.setAttributeName("value");
            mapping.setXPath("value");
            descriptor.addMapping(mapping);
            NamespaceResolver nr = new NamespaceResolver();
            descriptor.setNamespaceResolver(nr);
            oxSession.getProject().addDescriptor(descriptor);
            ((DatabaseSessionImpl)oxSession)
                .initializeDescriptorIfSessionAlive(descriptor);
            xrService.getXMLContext().storeXMLDescriptorByQName(descriptor);
        }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.sessions.Session

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.