How can I propagate properties into a nested sql fragment? - mybatis

I have an sql looks like this.
<sql name="level1">
${alias}some AS ${prefix}some
</sql>
Now I want to nest above fragment into another fragment while propagating those two properties.
<sql name="level2">
${alias}other AS ${prefix}other,
<include refid="level1">
<property name="alias" value="${alias}"/> <!-- will this "${alias}" work? -->
<property name="prefix" value="${prefix}"/> <!-- will this "${prefix}" work? -->
</include>
</sql>
My apologies, I should've tried for myself and saw what happened. But I'm working on a remote site and the testing environment is not complete.

Related

Ehcache seems not work

Now I want to use JPA second level cache by ehache. I made some configuration and it seems work. But I still can see the query sql. I'm not sure ehcache is working. Does anybody know about that? Thanks.
1.some part of persistence.xml
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory" />
<property name="hibernate.cache.provider_configuration" value="/ehcache.xml" />
<property name="hibernate.generate_statistics" value="true" />
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.show_sql" value="true" />
2.ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<defaultCache maxElementsInMemory="1" eternal="false"
timeToIdleSeconds="1200" timeToLiveSeconds="1200" overflowToDisk="true" clearOnFlush="true">
</defaultCache>
<cache name="org.test.persistent.entity.Scenario"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="1800"
timeToLiveSeconds="3600"
overflowToDisk="true">
</cache>
<cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
maxElementsInMemory="10000"
timeToIdleSeconds="1800"
timeToLiveSeconds="3600"
eternal="false">
</cache>
</ehcache>
3. sql
TypedQuery<Scenario> query = em.createQuery(
"from Scenario as s where s.obsolete!=1 and s.parentId=? order by s.name, s.scenarioStatusId",
Scenario.class);
query.setParameter(1, parentId);
query.setHint("org.hibernate.cacheable", true);
List<Scenario> scenarios = null;
org.hibernate.Query hbQuery = null;
if (query instanceof org.hibernate.ejb.QueryImpl) {
hbQuery = ((org.hibernate.ejb.QueryImpl)query).getHibernateQuery();
hbQuery.setCacheable(true);
scenarios = hbQuery.list();
} else {
scenarios = query.getResultList();
}
Ehcache setting is having its default value maxElementsInMemory="10000". It has to be tuned according to the hits.
One way to do this is, You can increase maxElementsInMemory and check if you want to solve this by "Trial and error" method.
Other way (reliable) is that you have to publish the Mbeans and watch for the cache usage and cache misses in JConsole. According to the report you can increase 'maxElementsInMemory'. Please refer how you should do that in http://hibernate-jcons.sourceforge.net/usage.html
I write cache data to disk by adding "". It seems work well and I find some data in the directory. But I still not find the reason of why it still execute sql.

Additional properties files for spring-batch-admin

I have a web application using spring-batch and I'm now integrating spring-batch-admin for basic administration.
The problem is that the jobs configuration files (which are shared with the configuration of the existing application) use properties from files in my application's classpath, but spring-batch-admin's context is not able to load them.
The quick solution was to override the placeholderProperties bean in spring-batch-admin just to add my properties files:
<bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/org/springframework/batch/admin/bootstrap/batch.properties</value>
<value>classpath:batch-default.properties</value>
<value>classpath:batch-${ENVIRONMENT:hsql}.properties</value>
<value>classpath:/path/to/jobs-config.properties</value> <!-- adding my properties here -->
</list>
</property>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="false" />
<property name="order" value="1" />
</bean>
I don't want to move my properties to one of spring-batch-admin's default files. Is there a simpler way to do this?
Answering my own question here...
As described in the documentation, every job configuration file placed under META-INF/spring/batch/jobs/*.xml is loaded by spring-batch-admin as a child context and property placeholders from the parent (i.e. this default bean) are inherited, but the child context can always create its own placeholder bean.
Given that, in my case, the job configuration files are shared with an existing application and use properties from the application classpath, the solution is to create a new job file in META-INF/spring/batch/jobs/*.xml specific for spring-batch-admin:
<!-- placeholder bean with additional properties for the child context -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/path/to/job-config.properties</value>
</list>
</property>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="false" />
<property name="order" value="1" />
</bean>
<!-- external job configuration file is imported -->
<import resource="classpath*:/path/to/job.xml" />

ATG-Endeca : Wild Card search configuration

I am wondering if there is a place where we can configure -- how many characters can be searched on for a wildcard. I am using ATG 10.1.2 and Endeca 3.1.2
Currently I am facing an issue in OOTB CRS application, if I search for one character and a '*' (asterisk), the search returns results, however when I do the same with 3 or more characters from the returned results, no results are returned. It returns again after 5 chars and a *.
I am testing this on the auto suggest feature in CRS, also tested the same on the endeca jspref app, same behavior.
I have searched for any flags that can be used to alter the configuration, but there are none as per http://docs.oracle.com/cd/E29584_01/webhelp/IAPAdmin/toc.htm#Dgraph%20flags
Help is appreciated!
UPDATE
I found that the wild card search was not enabled at all. The search query reaching the MDEX contained the * but the results only appeared for exact matches or after auto correction.
FIX
When I found that wildcard search was not working, I changed my schema.csv to contain the dimensions with wildcardsearch set to true. but that didn't help until I changed my
fcm.context.xml
changed the part starting with the comment as described below ::
<!-- this encodes the property default values from the schema feed xls spreadsheet -->
<bean id="propertyTemplate" class="com.endeca.itl.fcm.beans.PropertyConfiguration">
<property name="language" value="${LANGUAGE_ID}" />
<property name="isSearchable" value="false" />
<property name="isWildcardSearchable" value="true" />
<property name="isSortable" value="false" />
<property name="isFilterable" value="false" />
<property name="showOnListPage" value="true" />
<property name="showOnDetailPage" value="true" />
<property name="enableForRollup" value="false" />
</bean>
now it's working fine.

Activiti BPM Platform - Select a specific schema for creating tables?

I've just started working with activity and integrated it in my project (postgres based) in an embedded way (sample spring configuration file snip)
(...)
<!-- Activiti components -->
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
(...)
It works well and create a lot of tables on my application schema at startup.
My problem is : tables are created in the 'public' schema in my postgres database. I would have preferred to put those tables in a separate schema, say 'activity'.
Fact is that after browsing the documentation / the net for almost two hours, I didn't found any way to change the default schema target creation behavior.
Any help... greatly appreciated ! ;)
Since Postgres 9.4 JDBC driver you can specify the default schema in the JDBC url like this:
jdbc:postgresql://localhost:5432/mydatabase?currentSchema=myschema
With this URL, all Activiti tables are created in the myschema schema instead of the default one in the search path, usually public.
Sources: this response on Stack Overflow and the latest documentation.

Mybatis caching and concurrent modfications

I am using mybatis 3.0.4 for a test against a mysql 5.5 database with mysql-connector JDBC driver, version 5.1.16.
The problem I am experiencing is that if I get a SqlSession via openSession() method and i retrieve data via a select from database, subsequent selects in same session are not aware of changes made (and committed) to database even if i call clearCache() on session. To concurrently modify database I am using Mysql command line client. Setting cacheEnabled as false in configuration file doesn't help too.
I enclose configuration file.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-config.dtd">
<configuration>
<settings>
<setting name="lazyLoadingEnabled" value="false"/>
<setting name="cacheEnabled" value="false"/>
</settings>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="poolMaximumIdleConnections" value="20"></property>
<property name="poolMaximumActiveConnections" value="80"></property>
<property name="poolMaximumCheckoutTime" value="600"></property>
<property name="poolTimeToWait" value="600"></property>
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/testdb"/>
<property name="username" value="root"/>
<property name="password" value="password"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="mappers/TestMapper.xml" />
</mappers>
</configuration>
Ok, solved by myself. It was not a mybatis issue, it depended on Transaction isolation on JDBC driver, which was by default TRANSACTION_REPEATABLE_READ, I needed TRANSACTION_READ_COMMITTED instead. Solved with:
getSessionFactory().openSession(TransactionIsolationLevel.READ_COMMITTED);