Intersystems Cache使用XEP

时间:2014-10-02 15:54:40

标签: intersystems-cache intersystems intersystems-ensemble

我正在尝试从Intersystems Cache安装附带的Samples命名空间中提取数据。具体来说,我试图使用XEP检索Sample.Company全局数据。为了实现这一点,我创建了Sample.Company类 -

package Sample;

public class Company {

    public Long id;
    public String mission;
    public String name;
    public Long revenue;
    public String taxId;

    public Company(Long id, String mission, String name, Long revenue,
            String taxId) {
        this.id = id;
        this.mission = mission;
        this.name = name;
        this.revenue = revenue;
        this.taxId = taxId;
    }

    public Company() {
    }
}

XEP相关代码如下所示 -

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import Sample.Company;

import com.intersys.xep.Event;
import com.intersys.xep.EventPersister;
import com.intersys.xep.EventQuery;
import com.intersys.xep.EventQueryIterator;
import com.intersys.xep.PersisterFactory;
import com.intersys.xep.XEPException;

@Service
public class CompanyService {

    public List<Company> fetch() {
        EventPersister myPersister = PersisterFactory.createPersister();
        myPersister.connect("SAMPLES", "user", "pwd");
        try { // delete any existing SingleStringSample events, then import
                // new ones
            Event.isEvent("Sample.Company");
            myPersister.deleteExtent("Sample.Company");
            String[] generatedClasses = myPersister.importSchema("Sample.Company");
            for (int i = 0; i < generatedClasses.length; i++) {
                System.out.println("Event class " + generatedClasses[i]
                        + " successfully imported.");
            }
        } catch (XEPException e) {
            System.out.println("import failed:\n" + e);
            throw new RuntimeException(e);
        }
        EventQuery<Company> myQuery = null;
        List<Company> list = new ArrayList<Company>();
        try {
            Event newEvent = myPersister.getEvent("Sample.Company");
            String sql = "Select * from Sample.Company";
            myQuery = newEvent.createQuery(sql);
            newEvent.close();
            myQuery.execute();
            EventQueryIterator<Company> iterator = myQuery.getIterator();
            while (iterator.hasNext()) {
                Company c = iterator.next();
                System.out.println(c);
                list.add(c);
            }
            myQuery.close();
            myPersister.close();
            return list;
        } catch (XEPException e) {
            System.out.println("createQuery failed:\n" + e);
            throw new RuntimeException(e);
        }
    }

}

当我尝试执行上述类的fetch()方法时,我看到以下异常 -

 com.intersys.xep.XEPException: Cannot import - extent for Sample.Company not empty.
    at com.intersys.xep.internal.Generator.generate(Generator.java:52)
    at com.intersys.xep.EventPersister.importSchema(EventPersister.java:954)
    at com.intersys.xep.EventPersister.importSchema(EventPersister.java:363)

我得到了简单的字符串示例。这是否意味着,我们无法使用XEP读取现有数据?如果我们可以阅读,有人可以帮助我解决上述问题吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

您正在尝试在您的实例中创建一个名为Sample.Company的新类:

String[] generatedClasses = myPersister.importSchema("Sample.Company");

但是你仍然有数据和现有的课程。