Lucene教程 – Lucene索引文件 索引是识别文档并为搜索准备文档的过程。 下表列出了索引过程中常用的类。 类 描述 IndexWriter 在索引过程中创建/更新索引。 Directory 表示索引的存储位置。 Analyzer 分析文档并从文本中获取标记/单词。 Document 带有字段的虚拟文档。分析仪可以处理文档。 Field 索引过程的最低单位。它表示键值对,其中键用于标识索引值。 例子 以下代码显示了如何使用Lucene索引文本文件。 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT...
JPA教程 – JPA查询ANY示例 以下代码显示了如何在JPQL中使用ANY运算符。 List l = em.createQuery( "SELECT e FROM Professor e WHERE e.department = ANY (SELECT DISTINCT d FROM Department d)") .getResultList(); 例子 下面的代码来自PersonDaoImpl.java。 package cn.w3cschool.common; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.springframework.transaction.annotation.Transactional; @Transactional public class PersonDaoImpl { public void test() { prepareData(); List l = em.createQuery( "SELECT e FROM Professor e WHERE e.department = ANY (SELECT DISTINCT d FROM Department d)") .getResultList(); for (Object p : l) { printResult(p); } } private void prepareData() { Address address = new Address(); address.setState("BC"); Professor p = new Professor(); p.setId(0); p.setName("TOM"); p.setSalary(1111L); p.setAddress(address); Department d = new Department(); d.setId(1); d.setName("Design"); p.setDepartment(d); d.getProfessors().add(p); Phone phone = new Phone(); phone.setId(1); phone.setNumber("111-111-1111"); phone.setProfessor(p); em.persist(p); em.persist(phone); em.persist(address); em.persist(d); } private static void printResult(Object...
JPA教程 – JPA查询All示例 我们可以在JPQL中使用带有子查询的ALL运算符。 List l = em.createQuery( "SELECT e FROM Professor e WHERE e.salary < " + "ALL (SELECT d.salary FROM e.directs d)") .getResultList(); 例子 下面的代码来自PersonDaoImpl.java。 package cn.w3cschool.common; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.springframework.transaction.annotation.Transactional; @Transactional public class PersonDaoImpl { public void test() { prepareData(); List l = em.createQuery( "SELECT e FROM Professor e WHERE e.salary < " + "ALL (SELECT d.salary FROM e.directs d)") .getResultList(); for (Object p : l) { printResult(p); } } private void prepareData() { Professor p = new Professor(); p.setId(0); p.setName("TOM"); p.setSalary(1111L); Department d = new Department(); d.setId(1); d.setName("Design"); p.setDepartment(d); d.getProfessors().add(p); em.persist(p); em.persist(d); } private static void printResult(Object result) { if (result == null) { System.out.print("NULL"); } else if (result instanceof Object[]) {...
JPA教程 – JPA查询Not Empty示例 JPA SQL可以检查属性是否为空。 List l = em.createQuery( "SELECT p FROM Project p WHERE p.employees IS NOT EMPTY") .getResultList(); 例子 下面的代码来自PersonDaoImpl.java。 package cn.w3cschool.common; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.springframework.transaction.annotation.Transactional; @Transactional public class PersonDaoImpl { public void test() { prepareData(); List l = em.createQuery( "SELECT p FROM Project p WHERE p.employees IS NOT EMPTY") .getResultList(); for (Object p : l) { printResult(p); } } private void prepareData() { Address address = new Address(); address.setState("BC"); Professor p = new Professor(); p.setId(0); p.setName("TOM"); p.setSalary(1111L); p.setAddress(address); Department d = new Department(); d.setId(1); d.setName("Design"); p.setDepartment(d); d.getProfessors().add(p); Phone phone = new Phone(); phone.setId(1); phone.setNumber("111-111-1111"); phone.setProfessor(p); em.persist(p); em.persist(phone); em.persist(address); em.persist(d); } private static void printResult(Object result) { if (result == null) { System.out.print("NULL");...