<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Custom queries in Liferay(custom-sql)

    Prerequisites

    You should know how to create services with Service Builder. Also, you should know a little about SQL: the basic syntax and a notion on how it is used inside programming language code.

    The steps described here were performed over Liferay 6.0.6.

    Service.xml

    One part of service.xml :

    <entity name="Geschaeft" local-service="true" remote-service="false" table="Geschäfte">

        
    <!-- PK fields -->
        
    <column name="ID" db-name="[ID]" type="int" primary="true" />

        
    <!-- Other fields -->    
        
    <column name="Jahr" db-name="[Jahr]" type="Date" />
        
    <column name="Beschaffungsstrategie" db-name="[Beschaffungsstrategie]" type="String" />
        
    <column name="BuchVon" db-name="[Buch von]" type="String" />
        
    <column name="BuchNach" db-name="[Buch nach]" type="String" />
        
    <column name="Transaktionsdatum" db-name="[Transaktionsdatum]" type="Date" />
        
    <column name="Auftragsnummer" db-name="[Auftragsnummer]" type="String" />
        
    <column name="BeschaffungsZeitraumBeginn" db-name="[Besch#Zeitraum Beginn]" type="Date" />
        
    <column name="BeschaffungsZeitraumEnde" db-name="[Besch#Zeitraum Ende]" type="Date" />
        
    <column name="AnkaufVerkauf" db-name="[Ankauf/Verkauf]" type="String" />
        
    <column name="Geschaeftstyp" db-name="[Geschäftstyp]" type="String" />
        
    <column name="Produkt" db-name="[Produkt]" type="String" />
        
    <column name="LaufzeitVon" db-name="[Laufzeit von]" type="Date" />
        
    <column name="LaufzeitBis" db-name="[Laufzeit bis]" type="Date" />
        
    <column name="Sonderprodukt" db-name="[Sonderprodukt]" type="String" />
        
    <column name="KennzeichnungAuftraggeber" db-name="[Kennzeichnung des Auftraggebers]" type="String" />
        
    <column name="Abrechnungsrelevanz" db-name="[Abrechnungsrelevanz]" type="String" />
        
    <column name="FrueherePMSID" db-name="[Frühere PMS-ID oder Nr# Geschäftsimport]" type="String" /> 


        
    <!-- Order -->
        
    <order by="asc">
            
    <order-column name="Jahr" />
        
    </order>
            
    </entity>

     

    Let us beginning

    1.       Create a folder named “custom-sql” in source root.

    2.       Create a file named ” default.xml”, and type the following code. that mean that tell liferay to read others file from here.

    <?xml version="1.0"?>

    <custom-sql>
        
    <sql file="custom-sql/geschaeft.xml" />
        
    <sql file="custom-sql/otherTable.xml" />
        ..
        ..
    </custom-sql>

    3.       Create the .xml file which was added in default.xml.  and type the following code.

    <?xml version="1.0"?>

    <custom-sql>
        
    <sqlid="com.quantum.service.persistence.GeschaeftFinder.getAll">
          
    <![CDATA[
                SELECT
                        *
                FROM
                    Geschäfte
            
    ]]>
        
    </sql>
        
    <sql id="com.quantum.service.persistence.GeschaeftFinder.getList">
            
    <![CDATA[
                SELECT 
    CASE WHEN [Buch von] <> 'Standardbuch' THEN [Buch von] ELSE [Buch nach] END AS Portfolio,
                     [ID],
                     [Auftragsnummer]
                FROM Geschäfte
                WHERE CASE WHEN [Buch von] <> 'Standardbuch' THEN [Buch von] ELSE [Buch nach] END IN ('Spotmarkt','Krefeld A')
                AND [Frühere PMS-ID oder Nr# Geschäftsimport] NOT LIKE 'Q_%'
                AND Produkt <> 'intern_Spot'
                AND Produkt <> 'intern_EEG'
            
    ]]>
        
    </sql>
    </custom-sql>

     

     

    4.       Create a new class named “GeschaeftFinderImpl” in  com.quantum.service.persistence package, and extends BasePersistenceImpl, implements GeschaeftFinder which is not exist  so far. Don’t care about it. Continue type the following code:

    package com.quantum.service.persistence;

    import java.util.Iterator;
    import java.util.List;

    import com.liferay.portal.kernel.dao.orm.QueryUtil;
    import com.liferay.portal.kernel.dao.orm.SQLQuery;
    import com.liferay.portal.kernel.dao.orm.Session;
    import com.liferay.portal.kernel.dao.orm.Type;
    import com.liferay.portal.kernel.exception.SystemException;
    importcom.liferay.portal.service.persistence.impl.BasePersistenceImpl;
    import com.liferay.util.dao.orm.CustomSQLUtil;
    import com.quantum.model.Geschaeft;
    import com.quantum.model.impl.GeschaeftImpl;

    /**
     * 
     * 
    @author noah.xiang
     *
     
    */

    public class GeschaeftFinderImpl extendsBasePersistenceImpl<Geschaeft> implements GeschaeftFinder{
        
    private static String GETLIST = GeschaeftFinder.class.getName() + ".getList";
        
    private static String GETALL = GeschaeftFinder.class.getName() + ".getAll";

        
    public List<Geschaeft> getALL() throws SystemException {

            Session session 
    = null;

            
    try {
                session 
    = openSession();
                System.out.println(
    ">>>>>>>>>>>> "+ GETALL);
                String sql 
    = CustomSQLUtil.get(GETLIST);
                

                SQLQuery q 
    = session.createSQLQuery(sql);

                
    //q.addEntity("Geschäfte", GeschaeftImpl.class);
                q.addScalar("Portfolio", Type.STRING);
                q.addScalar(
    "ID", Type.INTEGER);
                q.addScalar(
    "Auftragsnummer", Type.STRING);

                Iterator
    <Object[]> itr = (Iterator<Object[]>)QueryUtil.iterate(q, getDialect(), -1-1);
                
    while (itr.hasNext()) {
                    Object[] array 
    = itr.next();
                    String portfolio 
    = (String)array[0];
                    
    int userId = (Integer)array[1];
                    String auftragsnummer 
    = (String)array[2];
                    System.out.println(
    ">>>>> "+ userId +"  "+ auftragsnummer+ " "+ portfolio);
                    
                }

                
    //List<Geschaeft> list = q.list();
                
                
    return null;
            }
     catch (Exception e) {
                
    throw new SystemException(e);
            }
     finally {
                closeSession(session);
            }

        }

    }

     

    5.       So far have many errors in your eclipse. But it doesn’t matter. Just ant build-service.xml. liferay will generate relevant code for us.

    6.       Find GeschaeftLocalServiceImpl class in com.quantum.service.impl package.  And create a method named public List<Geschaeft> getAll() throws SystemException. For the method you can rename whatever you want.

    public List<Geschaeft> getAll() throws SystemException{

                return geschaeftFinder.getALL();

          }

    7.       So far, all of configuration is finish. Go to action to call the method, like this:

    List<Geschaeft> geschaeft = GeschaeftLocalServiceUtil.getAll();

    8.       ant build-service.xml again. 

    9.       Wish you success! Think you.

     

     

    直接寫(xiě)的英文版的,不想再翻譯回來(lái)了。都不難理解,一看就能明白。不懂的請(qǐng)留言



    眼鏡蛇

    posted on 2011-10-27 17:44 眼鏡蛇 閱讀(2033) 評(píng)論(1)  編輯  收藏 所屬分類(lèi): Liferay

    評(píng)論

    # re: Custom queries in Liferay(custom-sql) 2013-05-08 13:30 Rasmi

    The entity that I'm creating doesnt have any columns, is that the reason why Finder and FinderUtil are not getting generated for me?  回復(fù)  更多評(píng)論   

    <2025年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(6)

    隨筆分類(lèi)

    隨筆檔案

    文章分類(lèi)

    文章檔案

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 特级淫片国产免费高清视频| 亚洲一区视频在线播放| 亚洲愉拍99热成人精品热久久| 亚洲AV无码成人精品区日韩| 免费无码精品黄AV电影| 亚洲国产视频一区| 久热中文字幕在线精品免费| 成人免费网站在线观看| 久久亚洲精品国产精品婷婷 | 亚洲一卡二卡三卡| 亚洲精品视频免费在线观看| 亚洲视频免费在线观看| 少妇太爽了在线观看免费视频| 78成人精品电影在线播放日韩精品电影一区亚洲 | 日本特黄特色AAA大片免费| 全免费a级毛片免费看| 亚洲国产精品无码久久一区二区 | 亚洲乱码国产乱码精华| 日本a级片免费看| 黄色一级视频免费| 精品亚洲一区二区| 免费观看无遮挡www的视频| 最新亚洲卡一卡二卡三新区| 日本高清免费不卡视频| 国产JIZZ中国JIZZ免费看| 亚洲精品无码成人AAA片| 亚洲精品在线免费看| 亚洲最大的成人网| 国产亚洲男人的天堂在线观看| 免费的一级黄色片| 久久久久免费视频| 国产无遮挡吃胸膜奶免费看视频| 午夜亚洲乱码伦小说区69堂| 色噜噜亚洲精品中文字幕| 2022久久国产精品免费热麻豆| 在线亚洲午夜片AV大片| 亚洲人成无码网WWW| 1000部拍拍拍18勿入免费视频下载| 亚洲日韩一区精品射精| 国产亚洲精品a在线观看| 风间由美在线亚洲一区|