I am new to esper. I want to store in mysql database event when esper identify event which satisfy the eql query.First i look up this example Esper: How to configure Esper to connect a Relational Database, through a JDBC, using Esper's configuration API and try to come up with solution.
<plugin-loader name="EsperIODBAdapter" class-name="com.espertech.esperio.db.EsperIODBAdapterPlugin">
<config-xml>
<esperio-db-configuration>
<jdbc-connection name="database">
<drivermanager-connection class-name="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/CEP_DEMO"
user="user" password="password"/>
<connection-settings auto-commit="true" catalog="TEST"/>
</jdbc-connection>
<dml connection="database" stream="event" >
<sql>INSERT INTO BasicEvent(userId,eventId,eventUsage,eventDateTime) values(?,?,?,?) </sql>
<bindings>
<bindings>
<parameter pos="1" property="userId"/>
<parameter pos="2" property="eventId"/>
<parameter pos="3" property="eventUsage"/>
<parameter pos="4" property="eventDateTime"/>
</bindings>
</bindings>
</dml>
</esperio-db-configuration>
</config-xml>
</plugin-loader>
Then when i run the application it didn't insert data to table.I want to know my method is correct or is there any other method to configuration.
Thanks
Maybe check that no exceptions are logged or thrown and the you are indeed inserting into a stream called "event" with "insert into event ..."
Related
I'd like to configure LocalDatastoreServiceTestConfig such that queries will fail if a compound index is needed (e.g., a query with a sort on multiple properties). Is there a way to do this?
I tried new LocalDatastoreServiceTestConfig().setNoIndexAutoGen(true) but it had no effect.
(There is a corresponding way to do this with the Python SDK.)
I assume by "fail" you mean "throw an exception" or something similar.
If so, you should set the autoGenerate attribute in your WEB-INF/datastore-indexes.xml to false.
Example WEB-INF/datastore-indexes.xml:
<datastore-indexes autoGenerate="false">
</datastore-indexes>
Setting autoGenerate to false will make a query that requires a composite index throw an exception.
Example code:
try {
Query q = new Query("Action")
.addSort("encrypter", Query.SortDirection.ASCENDING)
.addSort("requester", Query.SortDirection.ASCENDING)
.addSort("time", Query.SortDirection.DESCENDING);
//...snip...
} catch (Exception e) {
log.severe(e.toString());
}
I tested this and got an exception logged as expected:
SEVERE: com.google.appengine.api.datastore.DatastoreNeedIndexException: Query com.google.appengine.api.datastore.dev.LocalCompositeIndexManager$IndexComponentsO
nlyQuery#f9f81ad3 requires a composite index that is not defined. You must update C:\appengine-java-sdk\dev\core1\war\WEB-INF\datastore-indexes.xml or enable au
toGenerate to have it automatically added.
The suggested index for this query is:
<datastore-index kind="Action" ancestor="false" source="manual">
<property name="encrypter" direction="asc"/>
<property name="requester" direction="asc"/>
<property name="time" direction="desc"/>
</datastore-index>
For more information, see datastore-indexes.xml reference.
In my application, I use a pre determined log messages, something like this:
MESSAGE_ID PROCESS_ID This process is running
I would like to use a JDBC Appender and split my message in three, to get put each part in a particular SQL column.
Is this possible? And How?
Thanks a lot!
One idea is to use the ThreadContext to carry the message ID and process ID, and declare jdbc columns for each item like this:
<Column name="MESSAGE" pattern="%message" />
<Column name="MESSAGE_ID" pattern="%X{messageID}" />
<Column name="PROCESS_ID" pattern="%X{processID}" />
In your code you set the values like this:
ThreadContext.put("messageID", UUID.randomUUID().toString();
ThreadContext.put("processID", getProcessId());
...
logger.debug("this process is running");
...
I have a basic setup where the database is read by multiple web applications, and periodically I have a batch application which does a lot of writing. During the writing, the peroformance of the web-apps degrade heavily (their database reads are very slow).
The env. is MySQL db using MYISAM engine, the batch application is a Java SE app, using spring-batch and SimpleJDBCTemplate to issue SQL commands via JDBC. I found that MySQL has a parameter that lowers the priority of write operations on MYISAM engine: low_priority_updates. To quote the docs, amongs others, you can "SET LOW_PRIORITY_UPDATES=1 to change the priority in one thread". I opted for this because it's easiest from the config standpoint of my application. What I've done is configured my DataSource such that it exectutes that "SET ..." for each connection it opens, like so:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<!-- other props omitted -->
<property name="connectionInitSqls">
<list>
<value>SET low_priority_updates="ON"</value>
</list>
</property>
</bean>
Now my question is, how do I actually check that an SQL issued via this datasource does actually run with low priority? If I do SHOW FULL PROCESSLIST in MySQL while the inserts are happening it just tell me what SQL they're executing, nothing about the priority:
If I check the server variables low_priority_updates is "OFF" but that's just the server variable, it sais nothing about the thread-local value.
So again, is there any actual way to check if per query/thread low_priority_updates's values are taken into account?
By issuing SET LOW_PRIORITY_UPDATES=1 command, you are affecting the variable value for the session. Therefore it is possible to see this by checking the value of the variable in the session.
I know of two ways to do it:
1- SHOW SESSION VARIABLES LIKE 'low_priority_dapdates'
this shows ON/OFF
2- select ##session.low_priority_updates
this gives 0/1
Important: the above statements/calls will show you the values of the variables in the session where they run.
Therefore, you will need to run them using the connections themselves in order to see the values. I don't know of a way in MySQL where you can select values for variables that belong to another session.
If you would like to see them as a list, you might need to do a work around by creating a table and logging that info yourself. for example:
CREATE TABLE `mydb`.`my_low_priority_updates` (
`connection_id` INT ,
`low_priority_updates_value` INT NOT NULL
)
ENGINE = MyISAM;
then you need a statement that inserts the connection id and the value into the table:
insert into my_low_priority_updates(connection_id,low_priority_updates_value)
select connection_id(),##session.low_priority_updates
from dual
where not exists (select 1 from my_low_priority_updates where connection_id=connection_id())
you can put this statement in a procedure and make sure its called, or add it in a trigger on a table that you know gets updated/inserted into.
after that, querying the my_low_priority_updates table later will show you the values of the variable in each connection.
I'm trying to use iBatis to insert some data that get sent by a user in a contact us form.
I'm using a Liferay/Spring MVC/iBatis/MySQL setup but I think the problem is caused by the iBatis configuration. Whenever I try to insert data I see an exception in the logs:
com.ibatis.sqlmap.client.SqlMapException: There is no statement named contactus.ibatorgenerated_insert in this SqlMap.
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:231)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:367)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.insert(SqlMapClientImpl.java:58)
The ibator generated sql map does contain an insert query with id "ibatorgenerated_insert" with namespace "contact_us"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMapConfig>
<sqlMap namespace="contactus">
<insert id="ibatorgenerated_insert" parameterClass="contactUs.dao.ContactUs">
<!--
WARNING - This element is automatically generated by Apache iBATIS ibator, do not modify.
This element was generated on Thu Apr 07 15:17:57 BST 2011.
-->
insert into contactus (email_address, first_name, last_name, company, timestamp,
status, message)
values (#emailAddress:VARCHAR#, #firstName:VARCHAR#, #lastName:VARCHAR#, #company:VARCHAR#,
#timestamp:TIMESTAMP#, #status:VARCHAR#, #message:LONGVARCHAR#)
<selectKey resultClass="java.lang.Integer" keyProperty="contactusId">
SELECT LAST_INSERT_ID()
</selectKey>
</insert>
</sqlMap>
</sqlMapConfig>
What can be causing iBatis not to find the statement in the XML file? I assume that it's finding the file since it doesn't report any other kind of error.
I hope that you have specified the contactus.xml file which contains insert statement in the SqlMapConfig.xml as below
<sqlMapConfig>
<properties resource="Connection.properties"/>
<!-- Configure a built-in transaction manager. If you're using an app server, you probably want to use its transaction manager and a managed datasource -->
<settings cacheModelsEnabled="false" enhancementEnabled="true"
lazyLoadingEnabled="true" maxRequests="32" maxSessions="1"
useStatementNamespaces="false" />
<transactionManager type="JDBC">
<dataSource type="JNDI">
<property name="DataSource" value="${connection.datasource}"/>
</dataSource>
</transactionManager>
<!-- List the SQL Map XML files. They can be loaded from the classpath, as they are here (com.domain.data...) -->
<sqlMap resource="contactus.xml"/>
</sqlMapConfig>
Call without namespace.Something like below
sqlMapper.insert("ibatorgenerated_insert",params);
Try adding the following to your <sqlMapConfig> element:
<settings useStatementNamespaces="true"/>
I'm using Java and Ibatis to call a stored procedure on on oracle database. I seem to be having an issue setting up with parameters.
The store procedure looks like the following:
PROCEDURE Get_Semployees_By_Clt_ID
(
client_id IN HRIS.SEMPLOYEES.SEE_CLT_ID%TYPE,
ref_cursor OUT SYS_REFCURSOR
);
My Ibatis SqlMap:
<sqlMap namespace="Foo">
<resultMap id="employee-map" class="MyFoo">
<result property="foo1" column="foo1"/>
<result property="foo2" column="foo2"/>
</resultMap>
<parameterMap id="clientEmployeesParms" class="java.util.Map" >
<parameter property="in1" jdbcType="INTEGER" javaType="java.lang.Integer" mode="IN"/>
<parameter property="output1" jdbcType="ORACLECURSOR" javaType="java.sql.ResultSet" mode="OUT" />
</parameterMap>
<procedure id="clientEmployees" parameterMap="clientEmployeesParms" resultMap="employee-map">
{ call Package.Get_Clt_ID(?,?) }
</procedure>
</sqlMap>
My Java:
resource = "SqlMapConfig.xml";
reader = Resources.getResourceAsReader (resource);
sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
Map map = new HashMap();
map.put("in1", new Integer(23));
list = sqlMap.queryForList("Foo.clientEmployees", map);
Error:
--- The error occurred while applying a parameter map.
--- Check the Employee.clientEmployeesParms.
--- Check the output parameters (retrieval of output parameters failed).
--- Cause: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:188)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:123)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:610)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:584)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:101)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:78)
at com.apache.struts.employee.model.IbatisStoredProcedure.main(IbatisStoredProcedure.java:30)
I had the exact same problem. It is produced when you have iBatis prior to 2.1.5 and log4j in the classpath.
You can find more information here:
https://issues.apache.org/jira/browse/IBATIS-152
Update to iBatis 2.1.5 or remove log4j from classpath.
I work with iBatis.NET and Oracle and the way I was able to get the refcursor back from a stored procedure is as follows (Note that the output parameter is First in the list, and the property/column match the sproc:
<parameterMap id="GetServiceTypes-param">
<parameter property="P_CURSOR" direction="Output" column="P_CURSOR" dbType="RefCursor"/>
<parameter property="P_TYPSERVICETYPE" direction="Input" />
</parameterMap>
..
PROCEDURE GETSERVICETYPES(P_CURSOR OUT CURDATA,
P_TYPSERVICETYPE CLM_SERVICE_TYPES_TBL.SERVICETYPE%TYPE := NULL);
Peter. Are you going through bootcamp? (I work where you work, possibly in the same building. I'll shoot you an email tomorrow.)
I think the problem is because the resultMap needs to have the property names be the same as what is being returned by the procedure. In this case, whatever is being selected into the cursor.