I want to join two separate queries. And display information from them. First query is firms from Canada, second query is firms with name Incremento. So I need to run separate queries and join result information.
My schema is:
<entity name="firm" dataSource="jdbc" pk="id"
query="select * from firm"
deltaImportQuery="select * from firm where id='${dih.delta.id}'"
deltaQuery="select id from firm where upd_date > '${dih.last_index_time}'">
<field column="id" name="id"/>
<field column="ADDRESS" name="address"/>
<field column="EMPLOYEE" name="employee"/>
<field column="NAME" name="name"/>
<field column="VILLAGE" name="village"/>
<field column="ZIPCODE" name="zipcode"/>
<field column="PLACE" name="place"/>
<entity name="country" pk="id"
query="select country from country where id='${firm.country}'"
deltaQuery="select id from country where upd_date > '${dih.last_index_time}'"
parentDeltaQuery="select id from firm where country=${country.id}">
<field column="country" name="countryName"/>
</entity>
</entity>
How to do that ???
Searching :-
You can use e.g.
q=name:incremento&fq=location:Canada - Searches firms with name Incremento only in firms with location Canada
fq=location:Canada&fq=name:Incremento - Filters firms with Location CANADA and name Incremento
Indexing :-
You can either handle it in the SQL Query by using OR for compaines from Canada and ones with name Incremento.
e.g. SELECT * FROM FIRMS WHERE COUNTRY='CANADA' OR NAME='INCREMENTO'
OR DIH allows only tag. you may have multiple root tags. e.g.
<dataSource driver="..." url="..." user=".." />
<document name="companies">
<entity name="firm_canada" dataSource="jdbc" pk="id"
query="select * from firm"
deltaImportQuery="select * from firm where id='${dih.delta.id}'"
deltaQuery="select id from firm where upd_date > '${dih.last_index_time}'">
<field column="id" name="id"/>
....
</entity>
<entity name="firm_incremento" dataSource="jdbc" pk="id"
query="select * from firm where ..."
deltaImportQuery="select * from firm where id='${dih.delta.id}'"
deltaQuery="select id from firm where upd_date > '${dih.last_index_time}'">
<field column="id" name="id"/>
....
</entity>
</document>
</dataSource>
Related
I need to add a property to return a timestamp, I use below example to test print a sample date in "dataimport.properties" file to get last modified time. And it's not working
dataconfig.xml:
<dataConfig>
<dataSource type="JdbcDataSource"
driver="org.apache.cassandra.cql.jdbc.CassandraDriver"
url="jdbc:cassandra://localhost:9160/sample"
user="cassandra"
password="cassandra"
autoCommit="true"/>
<document name="content">
<entity name="defaults" query="SELECT id from sample.contacts"
deltaImportQuery="select id from sample.contacts where modifiedtime >'${dataimporter.defaults.last_index_time}' allow filtering"
deltaQuery="select id from sample.contacts where modifiedtime > '${dataimporter.last_index_time}' limit 1 allow filtering "
autoCommit="true">
<field column="id" name="id" />
</entity>
</document>
<propertyWriter dateFormat="yyyy-MM-dd" type="SimplePropertiesWriter" directory="conf" filename="dataimport.properties" locale="en-US"/>
</dataConfig>`
Try this
<propertyWriter dateFormat="yyyy-MM-dd" type="SimplePropertiesWriter" />
You will start getting your last_index_time in desired format (yyyy-MM-dd) in conf/dataimport.properties.
I'm very new to hibernate, and I'm trying to set up a new method in our PersonDAO.
My hibernate mapping file looks like this:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.foo.bar.domain">
<class name="Person" table="person">
<meta attribute="class-description">A Person</meta>
<id name="id" type="java.lang.Long" column="rid" unsaved-value="null">
<generator class="native" />
</id>
<version name="version" type="integer" column="rversion" unsaved-value="null" />
<property name="UID" type="string" column="UID" length="16" not-null="true" unique="true"/>
<property name="lastName" type="string" column="last_name" not-null="true" />
<property name="firstName" type="string" column="first_name" not-null="true" />
<property name="ownDepartment" type="string" column="own_department"/>
<!-- a person has many responsibilities and a responsibility can can assigned to many person -->
<set name="responsibilities" table="person_responsibility">
<key column="person_id"/>
<many-to-many column="responsibility_id" class="Responsibility"/>
</set>
<set name="additionalDepartments" table="PERSON_TO_ADDL_DEPARTMENT">
<key column="person_id"/>
<element column="ADDITIONAL_DEPARTMENT" type="string"/>
</set>
</class>
and I've written a method like this, in java, to fetch all the managers from a given department:
public List<Person> getManagerByDepartment(final String givenDepartment){
List<Person> l = (List<Person>) this.getHibernateTemplate().executeFind(new HibernateCallback<List<Person>>() {
public List<Person> doInHibernate(Session session) throws HibernateException, SQLException {
String query = "select p from Person p join p.responsibilities responsibilities join p.additionalDepartments additionalDepartments where responsibilities.name = 'manager' and (p.ownDepartment = :givenDepartment or additionalDepartments = :givenDepartment)";
List<Person> result = (List<Person>) session.createQuery(query).setString("givenDepartment", givenDepartment).list();
return result;
}
});
return l;
}
now I do a manual query in SQL, and I can see that for a given department, there are definitely more than one people who have the additional responsibility 'manager'...why does my method only ever return one person, instead of all of them?
I have a strong suspicion that my method, specifically my query, and not the mapping, is the issue, but I can't see what's wrong with it...
I've jumped in at the deep end here, so any help would be very much appreciated.
edit: note, I'm working on hundreds of records, not millions, and this isn't exactly a bottle-neck operation, so I'm not too worried about performance...that said if I'm doing something that's pointlessly wasteful, do point it out
You can print hibernate query by enabling showsql option and check the query getting created and then test it against the database.
Hard to be sure without the sample data, but when you do join in HQL, it is translated to inner join in SQL. So, if you know that there should be more than one result with given responsibility then the problem is probably join p.additionalDepartments.
Try this query with left join for additionalDepartments and see if it works
String query = "select p from Person p join p.responsibilities responsibilities left join p.additionalDepartments additionalDepartments where responsibilities.name = 'manager' and (p.ownDepartment = :givenDepartment or additionalDepartments = :givenDepartment)";
In Jasper Reports, how may I execute a sql query and store the result in a variable? This result should be accessed using $V{varName}.
EDIT: I have a subdataset defined like this:
<subDataset name="current_user" uuid="f8453e1d-8d55-4157-a8fd-aa04986e1cd5">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="MySQL Local"/>
<parameter name="u" class="java.lang.Integer">
<parameterDescription><![CDATA[]]></parameterDescription>
</parameter>
<queryString language="SQL">
<![CDATA[select first_name, last_name from users where id_user = $P{u}]]>
</queryString>
<field name="first_name" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="last_name" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
</subDataset>
I want the first and last name of a user, to be stored in a variable, and then this variable to be displayed in several fields (the variable is reused). How can I do that?
Your value come from sql query store in field. You can store that value in variable lie this.
First make variable and with same class of field which value you want to store in variable .
<variable name="variable" class="java.lang.String">
<initialValueExpression><![CDATA[$F{field1}]]></initialValueExpression>
</variable>
Where field1 is name of field which value you want to store in variable.
My db-data-config.xml like this:
<dataSource name="192.168.5.206" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.5.206:3306/editor_app" user="root" password="tvmining" />
<dataSource name="localhost" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.4.49/titans_myself" user="editor" password="tvm_editor" />
<document>
<entity dataSource ="192.168.5.206" name="product_info" query="SELECT t.id, t.title, t.keyword, t.update_time FROM product_info t" deltaQuery="SELECT t.id FROM product_info t where t.update_time > '${dataimporter.last_index_time}'" deltaImportQuery="SELECT t.id, t.title, t.keyword, t.update_time FROM product_info t where t.id='${dataimporter.delta.id}'">
<field column="id" name="id" />
<field column="title" name="title" />
<field column="keyword" name="keyword" />
<field column="update_time" name="update_time" />
</entity>
<entity dataSource ="localhost" name="log_info" query="SELECT t.id, t.operation_content FROM log_info t " deltaQuery="SELECT t.id, t.operation_content FROM log_info t where t.update_time > '${dataimporter.last_index_time}'" deltaImportQuery="SELECT t.id, t.operation_content FROM log_info t where t.id='${dataimporter.delta.id}'">
<field column="id" name="id" />
<field column="operation_content" name="operation_content" />
</entity>
</document>
but when I enter 'http://192.168.4.40:8080/solr/update/database?command=full-import', there always import the first entity data. How can I import two entities data?
this should work as is in order to import both entities. Now, maybe you expect to have a single doc in solr with fields from both entities if the id is the same?? If that is what you are looking for, you need to join the tables somehow, and use a single entity
Try with this url:
http://192.168.4.40:8080/solr/update/database?command=full-import&entity=log_info
I just added the entity parameter with the name of the entity as value.
I am trying the Data Import Handler for MySQL Database.
I added the DIhandler in solrconfig.xml, created a data-config.xml according to my database scheme and also added a field in the schema.xml which was different. I am connecting with MySQL database
After i connect and I run the dataimport?command=full-import i get this response
"00C:\solr\conf\data-config.xmlfull-importidle1102011-03-05 15:01:04Indexing completed. Added/Updated: 0 documents. Deleted 0 documents.2011-03-05 15:01:042011-03-05 15:01:040:0:0.400This response format is experimental. It is likely to change in the future."
The xml files are in this http://pastebin.com/iKebKGSZ
<field column="manu" name="manu" />
<field column="id" name="id" />
<field column="weight" name="weight" />
<field column="price" name="price" />
<field column="popularity" name="popularity" />
<field column="instock" name="inStock" />
<field column="includes" name="includes" />
Are these fields also in your schema.xml?
I couldnt see them in the pastebin link. Make sure you have all fields in your schema as well.