当前位置: 首页>>代码示例>>Java>>正文


Java Query类代码示例

本文整理汇总了Java中org.sql2o.Query的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Query类属于org.sql2o包,在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: importStuff

import org.sql2o.Query; //导入依赖的package包/类
public void importStuff(Path path) throws IOException {
	Stream<String> stream;
	if (!path.toFile().exists()
			&& new File(path.toFile().getPath() + ".gz").exists()) {
		path = Paths.get(path.toFile().getPath() + ".gz");
		stream = GZIPFiles.lines(path);
	} else
		stream = Files.lines(path);
	LOGGER.info("Starting import of {} into {}", path, tableName);
	final Iterator<String[]> iter = stream.map(x -> x.split(","))
			.iterator();
	long i = 1; //error if 0 due to criteria below
	Query query = null;
	try {
		while (iter.hasNext()) {
			if (query == null)
				query = sql2o.beginTransaction()
						.createQuery(String.format(sql, tableName));

			final String[] data = iter.next();
			addParameters(data, query).addParameter("corpus", corpusId)
					.addToBatch();
			//Nicer batch import leaks memory, thus using new connections is recommended
			++i;

			if ((i % IMPORT_BATCH_SIZE) == 0)
				query.executeBatch();
			if ((i % IMPORT_COMMIT_SIZE) == 0) {
				query.getConnection().commit();
				LOGGER.info("Finishd import of {}", i);
				query = null;
			}
		}
	} finally {
		if (query != null)
			query.executeBatch().commit();
	}
	LOGGER.info("Finished import of {} rows from {} into {}", i, path,
			tableName);
}
 
开发者ID:hellrich,项目名称:JeSemE,代码行数:41,代码来源:Importer.java

示例2: getHomePage

import org.sql2o.Query; //导入依赖的package包/类
@Override
public Class<? extends Page> getHomePage() {
    Sql2o sql2o = Spring.getBean(Sql2o.class);
    try (Connection connection = sql2o.open()) {
        Query query = connection.createQuery("SELECT groovy.java_class FROM setting INNER JOIN page on setting.value = page.page_id INNER JOIN groovy on page.groovy_id = groovy.groovy_id where setting.name = 'home_page'");
        String javaClass = query.executeAndFetchFirst(String.class);
        if (Strings.isNullOrEmpty(javaClass)) {
            return DashboardPage.class;
        } else {
            GroovyClassLoader classLoader = Spring.getBean(GroovyClassLoader.class);
            try {
                return (Class<? extends Page>) classLoader.loadClass(javaClass);
            } catch (ClassNotFoundException | ClassCastException e) {
                return DashboardPage.class;
            }
        }
    }
}
 
开发者ID:PkayJava,项目名称:MBaaS,代码行数:19,代码来源:Application.java

示例3: testUUID

import org.sql2o.Query; //导入依赖的package包/类
@Test
public void testUUID() throws Exception {

    try (Connection connection = sql2o.beginTransaction()) {
        connection.createQuery("create table uuidtest(id uuid primary key, val uuid null)").executeUpdate();

        UUID uuid1 = UUID.randomUUID();
        UUID uuid2 = UUID.randomUUID();
        UUID uuid3 = UUID.randomUUID();
        UUID uuid4 = null;

        Query insQuery = connection.createQuery("insert into uuidtest(id, val) values (:id, :val)");
        insQuery.addParameter("id", uuid1).addParameter("val", uuid2).executeUpdate();
        insQuery.addParameter("id", uuid3).addParameter("val", uuid4).executeUpdate();

        Table table = connection.createQuery("select * from uuidtest").executeAndFetchTable();

        assertThat((UUID)table.rows().get(0).getObject("id"), is(equalTo(uuid1)));
        assertThat((UUID)table.rows().get(0).getObject("val"), is(equalTo(uuid2)));
        assertThat((UUID)table.rows().get(1).getObject("id"), is(equalTo(uuid3)));
        assertThat(table.rows().get(1).getObject("val"), is(nullValue()));

        connection.rollback();
    }

}
 
开发者ID:lets-blade,项目名称:blade-jdbc,代码行数:27,代码来源:UUIDTest.java

示例4: save

import org.sql2o.Query; //导入依赖的package包/类
public <S extends Serializable> S save() {
    QueryMeta  queryMeta = SqlBuilder.buildInsertSql(this);
    Connection con       = getConn();
    log.debug(EXECUTE_SQL_PREFIX + " => {}", queryMeta.getSql());
    log.debug(PARAMETER_PREFIX + " => {}", this);
    Query query = con.createQuery(queryMeta.getSql()).bind(this);
    try {
        S s = (S) query.executeUpdate().getKey();
        if (null == Base.connectionThreadLocal.get() && !con.getJdbcConnection().getAutoCommit()) {
            con.commit();
        }
        return s;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:lets-blade,项目名称:blade-jdbc,代码行数:17,代码来源:ActiveRecord.java

示例5: invoke

import org.sql2o.Query; //导入依赖的package包/类
private int invoke(QueryMeta queryMeta) {
    log.debug(EXECUTE_SQL_PREFIX + " => {}", queryMeta.getSql());
    log.debug(PARAMETER_PREFIX + " => {}", Arrays.toString(queryMeta.getParams()));
    Connection con   = getConn();
    Query      query = con.createQuery(queryMeta.getSql()).withParams(queryMeta.getParams());
    if (queryMeta.hasColumnMapping()) {
        queryMeta.getColumnMapping().forEach(query::addColumnMapping);
    }
    int result = query.executeUpdate().getResult();
    try {
        if (null == Base.connectionThreadLocal.get() && !con.getJdbcConnection().getAutoCommit()) {
            con.commit();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return result;
}
 
开发者ID:lets-blade,项目名称:blade-jdbc,代码行数:19,代码来源:ActiveRecord.java

示例6: queryAll

import org.sql2o.Query; //导入依赖的package包/类
public <T> List<T> queryAll(Class<T> type, String sql, Object... args) {
    int pos = 1;

    while (sql.contains(SQL_QM)) {
        sql = sql.replaceFirst("\\?", ":p" + (pos++));
    }

    PageRow pageRow = Base.pageLocal.get();
    sql = SqlBuilder.appendPageParams(sql, pageRow);
    args = args == null ? new Object[]{} : args;

    try (Connection con = getSql2o().open()) {
        log.debug(EXECUTE_SQL_PREFIX + " => {}", sql);
        log.debug(PARAMETER_PREFIX + " => {}", Arrays.toString(args));
        this.cleanParam();
        Query     query     = con.createQuery(sql).withParams(args).throwOnMappingFailure(false);
        QueryMeta queryMeta = SqlBuilder.buildFindAllSql(this, null);
        if (queryMeta.hasColumnMapping()) {
            queryMeta.getColumnMapping().forEach(query::addColumnMapping);
        }
        return query.executeAndFetch(type);
    }
}
 
开发者ID:lets-blade,项目名称:blade-jdbc,代码行数:24,代码来源:ActiveRecord.java

示例7: find

import org.sql2o.Query; //导入依赖的package包/类
public <T extends ActiveRecord> T find() {
    QueryMeta queryMeta = SqlBuilder.buildFindSql(this);
    Class<T>  type      = (Class<T>) getClass();
    try (Connection con = getSql2o().open()) {
        this.cleanParam();

        log.debug(EXECUTE_SQL_PREFIX + " => {}", queryMeta.getSql());
        log.debug(PARAMETER_PREFIX + " => {}", Arrays.toString(queryMeta.getParams()));

        Query query = con.createQuery(queryMeta.getSql()).withParams(queryMeta.getParams()).throwOnMappingFailure(false);
        if (queryMeta.hasColumnMapping()) {
            queryMeta.getColumnMapping().forEach(query::addColumnMapping);
        }
        return query.executeAndFetchFirst(type);
    }
}
 
开发者ID:lets-blade,项目名称:blade-jdbc,代码行数:17,代码来源:ActiveRecord.java

示例8: insertSearchTimer

import org.sql2o.Query; //导入依赖的package包/类
public void insertSearchTimer(SearchTimer timer) {
    Sql2o sql2o = configuration.getSql2oEpg2vdr();

    try (Connection con = sql2o.beginTransaction()) {
        String sql = "INSERT INTO epg2vdr.searchtimers " + //
                "(inssp, channelids, chexclude, chformat, name, expression, expression1, searchmode, searchfields, searchfields1, casesensitiv, repeatfields, "
                + // "
                "episodename, season, seasonpart, category, genre, year, tipp, noepgmatch, type, state, namingmode, active, source, hits, vdruuid, weekdays, "
                + //
                "nextdays, starttime, endtime, directory, priority, lifetime, vps, childlock) " + //
                "VALUES(UNIX_TIMESTAMP(), :channelids, :chexclude, :chformat, :name, :expression, :expression1, :searchmode, :searchfields, :searchfields1, :casesensitiv, :repeatfields, "
                + //
                ":episodename, :season, :seasonpart, :category, :genre, :year, :tipp, :noepgmatch, :type, :state, :namingmode, :active, :source, :hits, :vdruuid, :weekdays, "
                + //
                ":nextdays, :starttime, :endtime, :directory, :priority, :lifetime, :vps, :childlock)";

        Query query = con.createQuery(sql);
        query.getParamNameToIdxMap().keySet().stream()
                .forEach(key -> query.addParameter(key, timer.getRawDbData().get(key)));
        query.executeUpdate();

        con.commit();
    }
}
 
开发者ID:Zabrimus,项目名称:vdr-jonglisto,代码行数:25,代码来源:EpgdSearchTimerServiceImpl.java

示例9: testSql2O

import org.sql2o.Query; //导入依赖的package包/类
@Test
public void testSql2O() throws SQLException, ParseException {
    Connection connection = DbHelper.objectDb();
    try {
        SingleConnectionDataSource scds = new SingleConnectionDataSource(connection, true);
        Sql2o sql2o = new Sql2o(scds);

        Query query = sql2o.open().createQuery(DbHelper.TEST_DB_OBJECT_QUERY);
        query.setAutoDeriveColumnNames(true);
        query.setResultSetHandlerFactoryBuilder(new SfmResultSetHandlerFactoryBuilder());

        List<DbObject> dbObjects = query.executeAndFetch(DbObject.class);

        assertEquals(1, dbObjects.size());
        DbHelper.assertDbObjectMapping(dbObjects.get(0));

    } finally {
        connection.close();
    }
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:21,代码来源:Sql2oIntegrationTest.java

示例10: getClosedInfo

import org.sql2o.Query; //导入依赖的package包/类
private Map<String, String> getClosedInfo() {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        c.set(Calendar.HOUR_OF_DAY, 0);

        Map<String, String> map = new HashMap<>();

        String sql = "select a.JH jh,a.RQ rq,b.DMMC dmmc,a.BZ bz FROM [email protected] a left join [email protected] b on a.bzdm=b.dm  where a.RQ=:dateTime " + //
                " and a.jh in (select code from t_end_tag where type='YOU_JING') and a.BZDM is not null ";

        try (Connection con = sql2o.open()) {
            org.sql2o.Query query = con.createQuery(sql);
            query.addParameter("dateTime", c.getTime());
            List<Row> dataList = query.executeAndFetchTable().rows();
            for (Row row : dataList) {
                String bz = row.getString("BZ") == null ? "" : ":" + row.getString("BZ");
                map.put(row.getString("jh"), row.getString("dmmc") + bz);
//                log.info(map.get(row.getString("jh")));
            }
        }
        return map;
    }
 
开发者ID:bcw104,项目名称:scada-oildata-webapp,代码行数:25,代码来源:CommonScdtServiceImpl.java

示例11: getChangTingClosedInfo

import org.sql2o.Query; //导入依赖的package包/类
/**
     * 三个月内生产时间平均值为0
     *
     * @return
     */
    private Map<String, String> getChangTingClosedInfo() {
        Calendar endTime = Calendar.getInstance();
        Calendar startTime = Calendar.getInstance();
        startTime.set(Calendar.MONTH, endTime.get(Calendar.MONTH) - 3);

        Map<String, String> map = new HashMap<>();

        String sql = "select * from (select avg(scsj) a,jh FROM [email protected] where jh in (select code from t_end_tag where type='YOU_JING')  "
                + " and rq>=:startTime and rq<=:endTime group by jh) "
                + " where a<1 ";

        try (Connection con = sql2o.open()) {
            org.sql2o.Query query = con.createQuery(sql);
            query.addParameter("startTime", startTime.getTime());
            query.addParameter("endTime", endTime.getTime());
            List<Row> dataList = query.executeAndFetchTable().rows();
            for (Row row : dataList) {
//                String bz = row.getString("BZ") == null ? "" : ":" + row.getString("BZ");
                map.put(row.getString("jh"), "CTJ");
                log.info(map.get(row.getString("jh")));
            }
        }
        return map;
    }
 
开发者ID:bcw104,项目名称:scada-oildata-webapp,代码行数:30,代码来源:CommonScdtServiceImpl.java

示例12: addParameters

import org.sql2o.Query; //导入依赖的package包/类
@Override
protected Query addParameters(final String[] s, final Query query) {
	query.addParameter("word", Integer.valueOf(s[0]));
	query.addParameter("year", Integer.valueOf(s[1]));
	query.addParameter("embedding",
			Joiner.on(" ").join(Arrays.copyOfRange(s, 2, s.length)));
	return query;
}
 
开发者ID:hellrich,项目名称:JeSemE,代码行数:9,代码来源:EmbeddingImporter.java

示例13: addParameters

import org.sql2o.Query; //导入依赖的package包/类
@Override
protected Query addParameters(final String[] s, final Query query) {
	query.addParameter("word1", Integer.valueOf(s[0]));
	query.addParameter("word2", Integer.valueOf(s[1]));
	query.addParameter("year", Integer.valueOf(s[2]));
	query.addParameter("association", Float.valueOf(s[3]));
	return query;
}
 
开发者ID:hellrich,项目名称:JeSemE,代码行数:9,代码来源:AssociationImporter.java

示例14: addParameters

import org.sql2o.Query; //导入依赖的package包/类
@Override
protected Query addParameters(final String[] s, final Query query) {
	query.addParameter("word", Integer.valueOf(s[0]));
	query.addParameter("year", Integer.valueOf(s[1]));
	query.addParameter("frequency", Float.valueOf(s[2]));
	return query;
}
 
开发者ID:hellrich,项目名称:JeSemE,代码行数:8,代码来源:FrequencyImporter.java

示例15: addParameters

import org.sql2o.Query; //导入依赖的package包/类
@Override
protected Query addParameters(final String[] s, final Query query) {
	query.addParameter("word", Integer.valueOf(s[0]));
	query.addParameter("year", Integer.valueOf(s[1]));
	query.addParameter("clob",
			Joiner.on(" ").join(Arrays.copyOfRange(s, 2, s.length)));
	return query;
}
 
开发者ID:hellrich,项目名称:JeSemE,代码行数:9,代码来源:CLOBImporter.java


注:本文中的org.sql2o.Query类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。