Remove comments in XML android - java

I'm working in eclipse and I would like to remove all the commentaries in my XML file in my code.
When there is no comment in my XML file, my application works. But as soon as I have any commentary in my XML file, my application stop working.
My question is : in android java, is there any way to remove with a code all the commentaries in my XML file?
I searched some keywords on google, but i don't find anything for java, only for C# or VB.
In those languages, they use something like "node" (I didn't really understood how it was working)
I join an example of XML file where there is the type of comment that I want to remove.
<?xml version="1.0" encoding="utf-8"?>
<pma_xml_export version="1.0" xmlns:pma="http://www.phpmyadmin.net/some_doc_url/">
<database name="mvc">
<!-- XML commentaries that i want to remove -->
<table name="hrd">
<column name="No_HRD">1</column>
<column name="Nom_HRD">H?tel Fleuritel</column>
<column name="Rue_HRD"> 1 Bd Jean Delautre</column>
<column name="CP_HRD">08000</column>
<column name="Ville_HRD"> Charleville-M?zi?re</column>
<column name="Tel_HRD"> 03 24 37</column>
<column name="Fax_HRD">03 24 37 5</column>
<column name="Email_HRD"> </column>
<column name="Image_HRD">1</column>
<column name="Site_HRD"> http://www.hotel-fleuritel.com</column>
<column name="No_Categorie_HRD">H</column>
<column name="No_Ville_HRD">1</column>
</table>
<!-- XML commentaries that i want to remove -->
<table name="hrd">
<column name="No_HRD">2</column>
<column name="Nom_HRD">Premi?re Classe CHARLEVILLE-MEZIERES</column>
<column name="Rue_HRD">Route de la Francheville ZAC Du MOULIN-LE-BLANC</column>
<column name="CP_HRD">08000</column>
<column name="Ville_HRD"> Charleville-M?zi?re</column>
<column name="Tel_HRD">08 92 70 7</column>
<column name="Fax_HRD"> 03 24 37</column>
<column name="Email_HRD">charlevillemezieres#premiereclasse.fr </column>
<column name="Image_HRD">3</column>
<column name="Site_HRD">http://www.premiere-classe-charleville-mezieres.fr</column>
<column name="No_Categorie_HRD">H</column>
<column name="No_Ville_HRD">1</column>
<!-- XML commentaries that i want to remove -->
</table>
<!-- XML commentaries that i want to remove -->
</database>
</pma_xml_export>

You don't have to get them out. You can just skip them. It is explained on the android development site. On this page.
If you go to the "read the feed" part you'll see that it will just skip it if it doesn't recognise it as a tag. If you do it this way it will just skip the commentary. I implemented this in my own project recently. So I can confirm that it works.

Related

Importing data from CSV using loadDate liquibase. Unknown columns creating an error

Let's say I have data.csv file with some data.
name, lastName, something, somethingElse
John, Doe , drinking , eating
I'm creating a table
<changeSet id="1" author="me">
<createTable tableName="myTable">
<column name="name" type="varchar(255)"/>
<column name="lastName" type="varchar(255)"/>
<column name="something" type="varchar(255)"/>
<column name="somethingElse" type="varchar(255)"/>
</createTable>
</changeSet>
I want to insert my data from data.csv
<changeSet author="me" id="2" runAlways="true">
<loadUpdateData encoding="UTF-8"
file="db/data.csv"
schemaName="liq"
separator=","
tableName="myTable">
<column name="name" type="varchar(255)"/>
<column name="lastName" type="varchar(255)"/>
<column name="something" type="varchar(255)"/>
<column name="somethingElse" type="varchar(255)"/>
</loadUpdateData>
</changeSet>
This piece of code works fine. In my situation, separator is ",".
I want to figure out different scenerio.
I get data2.csv file with unfinished (unnamed) columns. It was created for future inserts.
It looks like below:
name, lastName, something, somethingElse,,,,
John, Doe , drinking , eating ,,,,
So I have some extra comas which are separating non existing(yet) columns.
Is that possible to configure liquibase to skip or to do not read those specific comas? In current situation I will get
Reason: liquibase.exception.UnexpectedLiquibaseException: Unreferenced unnamed column is not supported
I have hundreds of rows and all of them contain comas at the end so removing them manually is pointless and not allowed in my situation.
Summing up I want to create table with only existing columns and insert data from
csv file. This file has extra comas at the end of each row, unfortunately
in same time comas are my columns separator. I checked list of properties and I didn't find anything useful.

Hibernate 5 and HBM Mapping issue, Schema-validation: missing table

I am taking an existing Java application and working on updating it from Hibernate 3 where we used hbm.xml files for Entity Mappings. We are now using Hibernate 5.5.5.Final and the code compiles with ehcache, but now I get an error with the code when starting to run it.
I should start off that one of the Hibernate properties is:
validate
The error message I am getting now is:
org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [my_db_dev.Project_myTemplateInfos]
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateTable(AbstractSchemaValidator.java:121)
at org.hibernate.tool.schema.internal.GroupedSchemaValidatorImpl.validateTables(GroupedSchemaValidatorImpl.java:42)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.performValidation(AbstractSchemaValidator.java:89)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.doValidation(AbstractSchemaValidator.java:68)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:200)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:81)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:327)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:471)
I would love to completely remove all the hbm.xml files and replace with them with Entity Mapping POJO's with annotations, however, that is not an option right now. The existing application has this different object model that goes throughout, so I don't want to mess with that right now. That will be in the next phase.
According to the error I am missing a table named 'Project_myTemplateInfos' and there is no table with this name. Instead, there is a table named 'Project' and the hbm.xml file for this is as follows.
<hibernate-mapping package="com.myApp.server.model">
<class name="Project" table="project" dynamic-update="true">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="name" not-null="true"/>
<property name="displayCity" not-null="true"/>
<list name="myTemplateInfos" cascade="all, delete-orphan" lazy="false" >
<key column="projectId" not-null="false" />
<list-index column="listIndex" />
<composite-element class="com.myApp.server.model.MyTemplateInfo" >
<property name="name" not-null="false" />
<property name="frequency" not-null="false" />
</composite-element>
</list>
</class>
</hibernate-mapping>
As you can see 'myTemplateInfos' is a List within the Project table. After the POJO is created, it looks like something like this.
#ModelBean(IProject.class)
#PermissionIdentifier("project")
public class Project extends ModelObject implements Serializable, IProject {
private Long id;
private String displayCity = "";
private List<IMyTemplateInfo> myTemplateInfos = Lists.newArrayList();
// getters and setters
// hashcode and equals
}
Next we do have another table in the database that is called 'myTemplateInfos' and we do have an hbm xml file for that table as follows ... actually we do not have an hbm xml file for this, so maybe that is the issue. I am going to create a hbm xml file for this and see if that solves the problem.
We do have a POJO for this object 'MyTemplateInfo' though.
If I simply remove his List from the hbm mapping and the Project object, the problem goes away of course, but there is another Set in the hbm.xml file which would give me the same problem, but with a new missing table.
The question becomes how to fix this error message. Is the problem within the hbm xml file for 'Project', or is it in the Project POJO, or the fact that an hbm file does not exist for the 'MyTemplateInfo'?
The solution to this was to fix the hbm xml mapping. Since I haven't had to do this in over 15 years, I am very rusty with it. I can't tell you how happy I was back then to switch to Java POJO's for Hibernate Entity classes with Annotations. But now, unfortunately, I am back having to deal with these xml files again.
The table I had 'mycommunitytemplateinfos' I created a new hbm xml file for it as follows, and put this in the hibernate.cfg.xml file before the other hbm xml mapping.
<hibernate-mapping package="com.myapp.server.model">
<class name="MyTemplateInfo" table="mytemplateinfos">
<id name="id" column="projectId">
<generator class="native"/>
</id>
<property name="name" not-null="false" />
<property name="frequency" not-null="false" />
</class>
</hibernate-mapping>
The mapping between this and the actual class is fine as I have tested this out. I put the hbm file in the hibernate.cfg.xml file before the Project.hbm.xml file and modified the Project.hbm.xml with a one-to-many tag as follows:
<list name="myTemplateInfos" cascade="all, delete-orphan" lazy="false" >
<key column="projectId" not-null="false" />
<list-index column="listIndex" />
<one-to-many class="com.myApp.server.model.MyTemplateInfo" />
</list>
And this seemed to work. I had to do something like this a few times until I got the mapping right. In this day of age, there isn't a lot of information about hbm xml files. Hibernate 5 does use these, but I understand that the preferred way is annotated Java POJO's. Unfortunately, I am stuck in a situation where I can't do that yet.

The filter mechanism in Hibernate hbm file is not very flexible for dynamic predicates

I am developing a Spring framework and hibernate application with a central database for an enterprise web application that has
about 1000 users online daily.
You can assume that there is a billing application and anybody can do anything on his own account (e.g. increase the amount of his billing or
decrease the amount of his billing).
Any user has its own data which is secured to the specific user by a mechanism of filtering in hbm files:
<?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 default-lazy="true">
<class name="org.myoffice.Inventory" table="Core_INVENTORY">
<id name="id" column="Id" type="java.lang.Long">
<generator class="sequence" >
<param name="sequence">SEQ_INVENTORY</param>
</generator>
</id>
<many-to-one name="bill" column="bill_ID" entity-name="org.myoffice.Bill" not-null="true" unique-key="unq_StrHouse_Smp_Pn_Exp"/>
<property name="expireDate" column="expire_Date" type="date" unique-key="unq_StrHouse_Smp_Pn_Exp"/>
<many-to-one name="user" column="user_id" entity-name="org.myoffice.User" not-null="true" update="false" />
<many-to-one name="createdBy" column="CreatedBy" entity-name="org.myoffice.User" not-null="true" update="false" />
<many-to-one name="updatedBy" column="UpdatedBy" entity-name="org.myoffice.User" not-null="true" />
<property name="createdDate" column="CreatedDate" type="date" not-null="true" update="false" />
<property name="updatedDate" column="UpdatedDate" type="date" not-null="true"/>
<property name="ip" column="IP" type="string" not-null="true"/>
<filter name="powerAuthorize" condition="[SQL QUERTY IS HERE FOR RESTRICTION ANY USER TO OWN DATA]"/>
</class>
</hibernate-mapping>
NOTE: The end of ([SQL QUERTY IS HERE FOR RESTRICTION ANY USER TO OWN DATA]) in above hbm is finished with a WHERE CLAUSE has userId parameter
for restricting a user to his own data and this userId is added the below method of generic repository.
And I add the powerAuthorize of hbm in my generic repository like this:
public void applyDefaultAuthorizeFilter(Session session) {
Filter filter = session.enableFilter("powerAuthorize");
filter.setParameter("userId", SecurityUtility.getAuthenticatedUser().getId());
}
This filter always add to end of any query for filtering data.
Everything had been working fine until the consumer of my application brought up a new demand which is not compatible with this current design. The consumer now wants to increase the billing of another user.
If I skip the filter hbm, any user will see the information of another user and if i dont skip the filter, I can't implement this new request.
Is there other mechanism, pattern or anything else I could use instead?
The #Filter is useful when the condition does not change, but just the bind parameter value can vary.
What you need here is to filter the WHERE clause predicate. Therefore, you need to move the filtering logic in your data access layer.
You write DAO methods to filter the Inventory based on user rights.
You remove the #Filter since the DAO methods will do that instead.
This design is much more flexible on the long term too.
You can use several filters and enable/disable them on demand. E.g. activate your "powerAuthorize" filter for all requests and just enable another filter "comprehensiveAuthorize" for your new requirement and disable "powerAuthorize" temporary.

Duke deduplication engine : exact same record not matched

I am attempting to use Duke to match records from one csv to another.First csv and second both has ID,Model,Price,CompanyName,Review,Url columns. I am trying to match to another csv to find duplicates records.
package no.priv.garshol.duke;
import no.priv.garshol.duke.matchers.PrintMatchListener;
public class RunDuke {
public static void main(String[] argv) throws Exception {
Configuration config =
ConfigLoader
.load("/home/kishore/Duke-master/doc/example-data/presonalCare.xml");
Processor proc = new Processor(config);
proc.addMatchListener(new PrintMatchListener(true, true, true, false, config.getProperties(),
true));
proc.link();
proc.close();
}
}
Here is an example of personalCare.xml:
<!-- language: xml -->
<!-- For more information, see https://github.com/larsga/Duke/wiki/ Improvements
needed: - some area numbers have spaces in them - not stripping accents from
names -->
<duke>
<schema>
<threshold>0.7</threshold>
<property type="id">
<name>ID</name>
</property>
<property>
<name>Model</name>
<comparator>no.priv.garshol.duke.comparators.Levenshtein</comparator>
<low>0.4</low>
<high>0.8</high>
</property>
<property>
<name>Price</name>
<comparator>no.priv.garshol.duke.comparators.ExactComparator</comparator>
<low>0.04</low>
<high>0.73</high>
</property>
<property>
<name>CompanyName</name>
<comparator>no.priv.garshol.duke.comparators.Levenshtein</comparator>
<low>0.4</low>
<high>0.8</high>
</property>
<property>
<name>Review</name>
<comparator>no.priv.garshol.duke.comparators.Levenshtein</comparator>
<low>0.12</low>
<high>0.93</high>
</property>
<property>
<name>Url</name>
<comparator>no.priv.garshol.duke.comparators.Levenshtein</comparator>
<low>0.12</low>
<high>0.93</high>
</property>
</schema>
<database class="no.priv.garshol.duke.databases.InMemoryDatabase">
</database>
<group>
<csv>
<param name="input-file" value="personal_care_11.csv" />
<param name="header-line" value="false" />
<column name="1" property="ID" />
<column name="2" property="Model" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
<column name="3" property="Price" />
<column name="4" property="CompanyName" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
<column name="5" property="Review" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
<column name="6" property="Url" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
</csv>
</group>
<group>
<csv>
<param name="input-file" value="personal_care_11.csv" />
<param name="header-line" value="false" />
<column name="1" property="ID" />
<column name="2" property="Model" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
<column name="3" property="Price" />
<column name="4" property="CompanyName" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
<column name="5" property="Review" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
<column name="6" property="Url" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
</csv>
</group>
</duke>
The above code is working fine but it does not match the exact record example
STHDRNFKAQ4AFYE8,Littmann 3M Classic II S.E Acoustic
Stethoscope,6297,Littmann,,http://dl.flipkart.com/dl/littmann-3m-classic-ii-s-e-acoustic-stethoscope/p/itme3uhzbqxhzfda?pid=STHDRNFKAQFAFYE8&affid=3ba0de4902524e2b90e43b84b89ea0ef
which is in both csv files. I also want to know the work of low and high property value which is given in .xml file, how to decide the low and high value for column value.
You are doing record linkage (two data sets) and not deduplication (single data set), so take out the .deduplicate() call.
Also, please don't use the 'no.priv.garshol.duke' package name. You should never use domain names you don't own yourself.
Anyway, the reason you can't find any matches is that the two records have the same ID. Duke verifies that it's not reporting records as matching themselves, and so the match gets filtered out. If you make a copy of the csv file and use that for group 2, then make a change to the ID then Duke finds the duplicate.
Here's what happens when I try that:
[lars.garshol#laptop tmp]$ java -cp ~/cvs-co/duke/duke-core/target/duke-core-1.3-SNAPSHOT.jar:. no.priv.garshol.duke.Duke --showmatches presonalCare.xml
MATCH 0.9982630751840313
ID: 'SHDRNFKAQ4AFYE8', Model: 'littmann 3m classic ii s.e acoustic stethoscope', Price: '6297', CompanyName: 'littmann', Url: 'http://dl.flipkart.com/dl/littmann-3m-classic-ii-s-e-acoustic-stethoscope/p/itme3uhzbqxhzfda?pid=sthdrnfkaqfafye8&affid=3ba0de4902524e2b90e43b84b89ea0ef',
ID: 'STHDRNFKAQ4AFYE8', Model: 'littmann 3m classic ii s.e acoustic stethoscope', Price: '6297', CompanyName: 'littmann', Url: 'http://dl.flipkart.com/dl/littmann-3m-classic-ii-s-e-acoustic-stethoscope/p/itme3uhzbqxhzfda?pid=sthdrnfkaqfafye8&affid=3ba0de4902524e2b90e43b84b89ea0ef',

JPA xml mapping not finding fields

I have the following class:
package lt.vic.valdos.domain.valda;
public class Valda implements java.io.Serializable {
private long id;
private Long valdosKodas;
public long getId() {
return id;
}
public Long getValdosKodas() {
return valdosKodas;
}
}
and the following orm.xml:
<?xml version="1.0"?>
<entity-mappings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_1.xsd"
version="2.1">
<entity class="lt.vic.valdos.domain.valda.Valda">
<table name="VALDOS" schema="VLD" />
<attributes>
<id name="id" />
<basic name="id">
<column name="vld_id" />
<return-insert return-only="true" />
</basic>
<basic name="valdosKodas">
<column name="valdos_kodas" />
</basic>
</attributes>
</entity>
</entity-mappings>
When I deploy this in glassfish, i get the following error:
Exception [EclipseLink-7215] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Could not load the field named [id] on the class [class lt.vic.valdos.domain.valda.Valda]. Ensure there is a corresponding field with that name defined on the class.
The class is in a jar that is included into a web application as a maven dependency. The orm.xml is in /WEB-INF/classes/META-INF of the web application.
What am I doing wrong?
Figured this one out myself. For some reason EclipseLink requires a setter on a class. Once I add private setters everything seems fine. Why the setters are needed (mapping accessors should default to FIELD) remains a mystery but it is not that important for me. Adding access="FIELD" to all entity attributes also fixes the problem without the setters.
You should be specifying the id as generated using the IDENTITY strategy:
<id name="id">
<column name="vld_id"/>
<generated-value strategy="IDENTITY"/>
</id>
This strategy will automatically read the database provided id back into the new object upon successful commit. The EclipseLink returning statement functionality is only applicable to basic mappings because id is already covered by Identity ID generation.
I think you have to add the column description for the id column to your id element, instead of using an extra basic element. As in <id name="id"> <column name="vld_id" /> ... </id>, without an extra <basic name="id"> ....
From my own experience (some time ago now), it's probably easier to use annotations to define your mappings.

Categories

Resources