Giter VIP home page Giter VIP logo

xcesco / kripton Goto Github PK

View Code? Open in Web Editor NEW
119.0 9.0 16.0 36.46 MB

A Java/Kotlin library for Android platform, to manage bean's persistence in SQLite, SharedPreferences, JSON, XML, Properties, Yaml, CBOR.

License: Apache License 2.0

Java 99.79% Batchfile 0.01% Shell 0.01% ANTLR 0.20% PLpgSQL 0.01%
java android-platform java-library annotation-processor annotations cbor xml json sqlite-android sqlite

kripton's Introduction

Android Weekly Android Arsenal maven central test coverage Project Stats Build Status

Thanks to JetBrains for support Kripton Persistence Library project!

Kripton Persistence Library

Kripton is a java library, for Android platform, that provides a simple and uniform way to manage persistence of Java classes in different flavours through annotations and interface. Kripton can do for you:

  • generate all the code necessary to persist your POJO in a SQLite database (Light-ORM functionality). It's support Live Data and Androidx JetPack.
  • generate all the code necessary to convert POJO object in different data format: JSON, XML, CBOR, properties, YAML
  • generate all the code to persist your POJO in Shared Preferences. It's support Live Data and Androidx JetPack.
  • Kripton can be integrated to Retrofit library to generate all code necessary to JSON-2-Java convertion without any reflection code.
  • You can use Kripton with Kotlin too.

Does it sound interesting? I hope so! :)

The Kripton's key features are summarized in the following image.

Screenshot 2020-11-06 at 21 56 58

To get max performance and avoid boilerplate-code, Kripton use annotation processor. With the power of annotation processor is possible to create code to persist a java class, simply with an annotation. There are many other libraries that do this, but Kripton allows to persists java object without using reflection and with just few lines of code.

Kripton is fully working with Kotlin too.

See wiki for more informations.

See benchmarks for more informations about SQLite and JSON persistence perfomance.

If you are interested in Kripton Persistence Library, visit abubusoft.com

Setup

Kritpon requires at minimum Java 8 or Android 3.0.

Gradle configuration

You can use Kritpon Annotation Processor and Kripton Persistence Library via gradle

// annotation processor
annotationProcessor "com.abubusoft:kripton-processor:${kripton-version}"

// https://mvnrepository.com/artifact/com.abubusoft/kripton
implements "com.abubusoft:kripton-android-library:${kripton-version}"

Code configuration

Before use Kripton to persit on SQLite and Shared Preferences, an Android app have to initialize Kripton library. To do this, just add the following code to Application class (usually on method onCreate):

// set context for Kripton Library
KriptonLibrary.init(this);

Quickstart - Persistence on a SQLite database

Kripton uses the DAO pattern to approach the database management. In the DAO pattern there are:

  • A data model composed of simple POJO objects in Java world, and tables in the SQLite world.
  • Data Access Object interfaces that define how to access to the database
  • Data Access Object implementation that implements the DAO interfaces
  • A database that is composed of DAOs and data model.

Choose the right database

In version 7 Kripton you can choose to use plain SQLite databases or ciphered database through the SQLCipher database.

Use SQLite

To use simple SQLite database, simply add to project's dependencies the sqlite aar

implementation "androidx.sqlite:sqlite:2.1.0"

Use SQLcipher

To enable this feature, just include in your dependencies the sqlcipher aar:

implementation "net.zetetic:android-database-sqlcipher:4.3.0"

And use the KriptonSQLCipherHelperFactory to as factory in your DataSources:

KriptonSQLCipherHelperFactory factory = new KriptonSQLCipherHelperFactory(password.toCharArray());

BindAppDataSource.build(DataSourceOptions.builder()
        .populator(new AppPopulator())
        .openHelperFactory(factory)
        .build());

Model definition example

Kripton needs the developer defines the data model with @BindTable annotated java classes, the DAO’s interfaces with BindDao annotated Java interface and a data source (the database) by a BindDataSource annotated Java interface. At compile time, Kripton will generate all needed code to implements DAO interfaces and for managing data source.

Suppose that our app data model has a Person entity that need to be persisted on a SQLite databas. In the following example it is explained how to define an SQLite database with a person table, and a DAO interface with some methods to do CRUD operations (Create Read Update Delete). The data model:

@BindSqlType(name="persons")
public class Person{
  public long id;
  public String name;
  public String surname;
  public String email;
  public Date birthDate;
}

Just two things:

  • every SQLite table needs an id column of type Long or long. It’s a constraint that Kripton required for every table and it is a best practice for SQLite databases.
  • @BindSqlType is the annotation used to mark a data model that will be used in an SQLite database.

The DAO interface definition is:

@BindDao(Person.class)
public interface PersonDao {

  @BindSqlSelect(orderBy="name")
  List<Person> selectAll();

  @BindSqlSelect(jql="select * from person order by name")
  List<Person> selectTwo();

  @BindSqlSelect()
  List<Person> selectThree(@BindSqlDynamicOrderBy String orderBy);

  @BindSqlSelect(where = "id=${work.id}")
  List<E> selectById(@BindSqlParam("work") E bean);

  @BindSqlInsert
  void insert(Person bean);

  @BindSqlUpdate(where = "id=${work.id}")
  boolean update(@BindSqlParam("work") Person bean);
  
  @BindSqlDelete(where = "id=${work.id}")
  boolean delete(@BindSqlParam("work") Person bean);
}

The data source definition:

@BindDataSource(daoSet= { PersonDao.class }, fileName = "person.db", log=true)
public interface PersonDataSource {
}

When the project is compiled, Kripton annotation processor will generate for us the code that implements the data source defined by the data model, the DAO and data-source interfaces.

The need annotations to define a data source with Kripton are:

In the application, to use generated an implementation of data-source you can use code like this:

// typically Kripton library is done in Application#onCreate
KriptonLibrary.init(context);

// usage example 1: using a transaction
BindPersonDataSource.getInstance().execute(daoFactory -> {
    PersonDao dao=daoFactory.getPersonDao();
    dao.insert(person);
    ...
    return TransactionResult.COMMIT;
});

// usage example 2: using shared connection
BindPersonDataSource.getInstance().executeBatch(daoFactory -> {
    PersonDao dao=daoFactory.getPersonDao();
    dao.selectAll();
    ...

});

For a PersonDataSource interface, Kripton generates a BindPersonDataSource class that implements the data-source which allows to work in a thread-safe way and exposing all DAO defined in PersonDataSource interface. The generated data-source exposes some methods to work in a transaction mode and in shared connection mode.

Quickstart - data format and REST clients

Suppose that your application data model is composed by User entity so defined (getter and setter are omitted for simplicity):

@BindType
public class User {
    public long id;
    public String name;
    public String username; 
}

To store or read an instance of User on a file, you can simply write:

// HOW TO WRITE/READ ON A FILE IN JSON FORMAT
// define an object
User user=new User();
...
				
// WRITE ON A FILE				
BinderContext binder=KriptonBinder.jsonBind();
binder.parse(new File(...), user);
...

// DEFINE A PERSISTENCE BINDER
BinderContext binder=KriptonBinder.jsonBind();

// WRITE INTO A FILE				
binder.serialize(user, new File(..));

// READ FROM A FILE				
User newUser=binder.parse(new File(..), User.class);

To make same operation with different data format like XML, YAML, and so on just replace

BinderContext binder=KriptonBinder.jsonBind();

with

// XML binder
BinderContext binder=KriptonBinder.xmlBind();

// YAML binder
BinderContext binder=KriptonBinder.bind(BinderType.YAML);

// CBOR binder
BinderContext binder=KriptonBinder.bind(BinderType.CBOR);

// PROPERTY binder
BinderContext binder=KriptonBinder.bind(BinderType.PROPERTIES);

// SMILE binder
BinderContext binder=KriptonBinder.bind(BinderType.SMILE);

To integrate Kripton Persistence Library with Retrofit:

// Client definition
public interface QuickStartService {
  @GET("users")
  Call<List<User>> listUsers();	
}

// Retrofit initialization (with Kripton converter factory)
Retrofit retrofit = new Retrofit.Builder().baseUrl(...)
  .addConverterFactory(KriptonBinderConverterFactory.create())
  .build();

// Retrofit usage
.. as usual.

To see how fast is Kripton to convert from/to JSON read this wiki page.

Quickstart - Persistence with Shared Preferences

To persist beans with SharedPreference, we need to define the class that contains properties that SharedPreference will persist.

Kritpon uses an annotation processor to generate boilerplate code necessary to interact with shared preferences.

Usage

Consider the follow bean definition:

@BindType
public class User  {
    public long id;
    public String email;
    public String name;
    public String surname;
    public String username;
}

A share preferences definition can be done with a simple class:

@BindSharedPreferences
public class SecurityPreferences {
  public User user;
}

The Kripton Annotation Processor will generate for us BindSecurityPreferences to work with shared preferences. In this way, after run the annotation processor, to work with shared preferences we will write:

final User bean=new User();
...
BindSecurityPreferences security=BindSecurityPreferences.getInstance();
security.edit().putUser(bean).commit();	

There some feature of generated shared preference that we want to underline:

  • BindSecurityPreferences derives from Shared Preference, so it inherit all its method and its "way of working".
  • BindSecurityPreferences is a singleton.
  • Shared Preferences can be managed with Live Data and Observable pattern (since version 4).
  • BindSecurityPreferences contains a Editor specialized to work with SecurityPreferences fields.

Build

To build entire library collections just download repository and launch from base directory

mvn clean install -Prelease

Supported platforms

There are two supported platforms: the android environment and generic Java environment. For each platform there is a version of library. Android platform already include a json library and xml parser library. Java JDK does not include a json library and have different xml parser libraries.

License

Copyright 2015-2020 Francesco Benincasa.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

kripton's People

Contributors

dependabot[bot] avatar ron-k avatar xcesco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kripton's Issues

Wrong binding on

Model:

@BindType
public class Document {
  public long id;
  public String fileName;
}

@BindDao(Document.class)
public interface DaoDocument {	
  @BindSqlSelect(fields="fileName",where="fileName like :input")
  Set<String> findByFileName(String input);
	
  @BindSqlInsert
  void insert(String fileName);

  @BindSqlSelect
  List<Document> selectAll();
}

When I try to invoke findByFilename I receive the following error:

com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'sorry': was expecting ('true', 'false' or 'null')

Support for androidx.sqlite.db

With androidx packages, a new sqlite wrapper is coming: androidx.sqlite.db. We need to include its support. It's the way to support in the future other SQLite library implementation (SQLCypher in primis).

Sometimes java.lang.IllegalStateException: attempt to re-open an already-closed object

Improve open in-write-mode check.

java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: xxxx
at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
at android.database.sqlite.SQLiteDatabase.isDbLockedByCurrentThread(SQLiteDatabase.java:602)
at com.abubusoft.kripton.android.sqlite.AbstractDataSource.isOpenInWriteMode(AbstractDataSource.java:499)

Allow in XML format parser to have sparse elements of a flat array

I decide to avoid to implement this feature because it will break the compatibility with JSON and other data format supported by Jackson. Better to allow in XML format to have elements of a flat array (the one with no tag for an array, but only for the array items). An example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<containerBean>
  <item><name>ciuaua</name></item>
  <name>hello</name>
  <item><name>ciuaua</name></item>
</containerBean>

The new goal is that associated Java object can put in it list field item both elements. For the moment only the last will be captured.

Originally posted by @xcesco in #43 (comment)

SQLite: use % symbol in where condition

Consider the case:

@BindSqlSelect(where="name like ${name} || '%%' ", orderBy="name")
Set selectAll(String name);

When converted in its implemetation, it become:
...
Logger.info(StringUtils.formatSQL("SELECT id, name, surname, birth_city, birth_day FROM person WHERE name like '%s' || '%%' ORDER BY name"),(Object[])args);
Cursor cursor = database().rawQuery("SELECT id, name, surname, birth_city, birth_day FROM person WHERE name like ? || '%%' ORDER BY name", args);
...

In rawQuery row, % have to be converted in %% in log string and remain % in sql string.

Generated content provider does not compile (updateWithOnConflict)

Let DAO method annotated with the following:

@BindContentProviderEntry(path = "${pref.verticalId}")
   @BindSqlUpdate(conflictAlgorithm = ConflictAlgorithmType.IGNORE, where = "verticalId=${pref.verticalId}")
   int update(VerticalPref pref);

The combination of conflictAlgorithm and where in the annotation @BindSqlUpdate generates a code with compilation error, as following (note the extra ')' before ", 4"):

int result = database().updateWithOnConflict("vertical_pref", contentValues.values(), sqlWhereStatement, _contentValues.whereArgsAsArray()), 4);

xml parser does not skip correctly unknown tags

Use case:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1  -->
<jasperReport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
			  xmlns="http://jasperreports.sourceforge.net/jasperreports"
			  xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"
			  name="ricetta" pageWidth="595" pageHeight="421" columnWidth="555" leftMargin="20" rightMargin="20"
			  topMargin="20" bottomMargin="20" uuid="dfcc67f8-27a8-4010-90a8-70d1d9f2f28d">
	<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sanita Ricetta"/>
	<property name="com.jaspersoft.studio.unit." value="pixel"/>
	<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
	<queryString>
		<![CDATA[]]>
	</queryString>
	<field name="regione" class="java.lang.String">
		<fieldDescription><![CDATA[regione]]></fieldDescription>
	</field>
	<field name="cognomeNome" class="java.lang.String">
		<fieldDescription><![CDATA[cognomeNome]]></fieldDescription>
	</field>
	<field name="indirizzo" class="java.lang.String">
		<fieldDescription><![CDATA[indirizzo]]></fieldDescription>
	</field>
	<field name="cap" class="java.lang.String">
		<fieldDescription><![CDATA[cap]]></fieldDescription>
	</field>
	<field name="citta" class="java.lang.String">
		<fieldDescription><![CDATA[citta]]></fieldDescription>
	</field>
	<field name="provincia" class="java.lang.String">
		<fieldDescription><![CDATA[provincia]]></fieldDescription>
	</field>
	<field name="codiceFiscale" class="java.lang.String">
		<fieldDescription><![CDATA[codiceFiscale]]></fieldDescription>
	</field>
	<field name="nreRegioneProvincia" class="java.lang.String">
		<fieldDescription><![CDATA[nreCodiceRegioneProvincia]]></fieldDescription>
	</field>
	<field name="nreLottoProgressivo" class="java.lang.String">
		<fieldDescription><![CDATA[nreLottoProgressivo]]></fieldDescription>
	</field>
	<field name="esenzione" class="java.lang.String">
		<fieldDescription><![CDATA[esenzione]]></fieldDescription>
	</field>
	<field name="assistitoProvincia" class="java.lang.String">
		<fieldDescription><![CDATA[assistito provincia]]></fieldDescription>
	</field>
	<field name="codiceASL" class="java.lang.String">
		<fieldDescription><![CDATA[codice ASL]]></fieldDescription>
	</field>
	<field name="disposizioniRegionali" class="java.lang.String">
		<fieldDescription><![CDATA[disposizioni regionali]]></fieldDescription>
	</field>
	<field name="tipologiaPrescrizione" class="java.lang.String">
		<fieldDescription><![CDATA[tipologiaPrescizione]]></fieldDescription>
	</field>
	<field name="altro" class="java.lang.String">
		<fieldDescription><![CDATA[altro]]></fieldDescription>
	</field>
	<field name="priorita" class="java.lang.String">
		<fieldDescription><![CDATA[priorita]]></fieldDescription>
	</field>
	<field name="diagnosi" class="java.lang.String">
		<fieldDescription><![CDATA[diagnosi]]></fieldDescription>
	</field>
	<field name="tipoRicetta" class="java.lang.String">
		<fieldDescription><![CDATA[tipo ricetta]]></fieldDescription>
	</field>
	<field name="totaleConfezioni" class="java.lang.String">
		<fieldDescription><![CDATA[totaleConfezioni]]></fieldDescription>
	</field>
	<field name="dataCompilazione" class="java.lang.String">
		<fieldDescription><![CDATA[dataCompilazione]]></fieldDescription>
	</field>
	<field name="medicoPrescrittoreCodiceFiscale" class="java.lang.String">
		<fieldDescription><![CDATA[medico prescrittore codice fiscale]]></fieldDescription>
	</field>
	<field name="medicoPrescrittoreCognomeNome" class="java.lang.String">
		<fieldDescription><![CDATA[medico prescrittore cognome nome]]></fieldDescription>
	</field>
	<field name="codiceAutenticazione" class="java.lang.String">
		<fieldDescription><![CDATA[codiceAutenticazione]]></fieldDescription>
	</field>
	<field name="promemoria" class="java.lang.String">
		<fieldDescription><![CDATA[promemoria]]></fieldDescription>
	</field>
	<field name="righe" class="java.util.List">
		<fieldDescription><![CDATA[Elenco delle righe]]></fieldDescription>
	</field>
	<field name="riga1" class="java.lang.String">
		<fieldDescription><![CDATA[Riga 1]]></fieldDescription>
	</field>
	<background>
		<band splitType="Stretch"/>
	</background>
	<title>
		<band height="210" splitType="Stretch">
			<rectangle>
				<reportElement x="8" y="16" width="542" height="60" uuid="f68be353-a14c-4502-bdc6-324d7d0aadea">
					<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
					<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
				</reportElement>
			</rectangle>
			<textField>
				<reportElement x="13" y="24" width="180" height="30" uuid="020e3373-1778-4347-80c0-a79d9605e0fd"/>
				<textFieldExpression><![CDATA[$F{regione}]]></textFieldExpression>
			</textField>
			<staticText>
				<reportElement x="10" y="0" width="214" height="16" uuid="5afbf083-2e2c-4a44-bef3-dace4d6a289c"/>
				<textElement>
					<font size="8"/>
				</textElement>
				<text><![CDATA[SERVIZIO SANITARIO NAZIONALE]]></text>
			</staticText>
			<staticText>
				<reportElement x="330" y="0" width="230" height="16" uuid="43881300-c76b-4af7-852d-46ed539d8c92"/>
				<textElement>
					<font size="8"/>
				</textElement>
				<text><![CDATA[RICETTA ELETTRONICA - PROMEMORIA PER L'ASSISTITO]]></text>
			</staticText>
			<line>
				<reportElement x="213" y="16" width="1" height="60" uuid="67fabd44-30fa-464e-a8f6-bfb4e51de81c">
					<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
				</reportElement>
			</line>
			<componentElement>
				<reportElement x="222" y="20" width="110" height="30" uuid="9efded0e-07e8-4a6f-807c-59a1628c7b1a">
					<property name="com.jaspersoft.studio.unit.barHeight" value="pixel"/>
					<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
				</reportElement>
				<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components"
							 xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"
							 type="Code39" drawText="false" checksumRequired="false">
					<jr:codeExpression><![CDATA[$F{nreRegioneProvincia}]]></jr:codeExpression>
				</jr:barbecue>
			</componentElement>
			<textField>
				<reportElement x="222" y="57" width="110" height="16" uuid="ccf51acf-421b-457b-9565-d0e222b96c48"/>
				<textFieldExpression><![CDATA["*"+$F{nreRegioneProvincia}+"*"]]></textFieldExpression>
			</textField>
			<componentElement>
				<reportElement x="341" y="20" width="190" height="30" uuid="9627d7dd-5bc9-4d31-baad-635ac940f6d9">
					<property name="com.jaspersoft.studio.unit.barHeight" value="pixel"/>
				</reportElement>
				<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components"
							 xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"
							 type="Code39" drawText="false" checksumRequired="false">
					<jr:codeExpression><![CDATA[$F{nreLottoProgressivo}]]></jr:codeExpression>
				</jr:barbecue>
			</componentElement>
			<textField>
				<reportElement x="341" y="56" width="190" height="16" uuid="7068510e-e7b5-45a7-a122-464756a55ab9"/>
				<textElement textAlignment="Center"/>
				<textFieldExpression><![CDATA["*"+$F{nreLottoProgressivo}+"*"]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="0" y="80" width="275" height="18" uuid="b7f67928-dae2-4b3c-b6a6-c5823f3db118"/>
				<textFieldExpression><![CDATA[$F{cognomeNome}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="0" y="111" width="270" height="28" uuid="acd9ac3e-86a7-4d30-8d89-480275eb5a52"/>
				<textFieldExpression><![CDATA[$F{indirizzo}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="340" y="121" width="92" height="18" uuid="55ed3d45-c7ec-4967-9e30-bc301a310803"/>
				<textFieldExpression><![CDATA[$F{citta}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="430" y="121" width="38" height="18" uuid="f3af7712-57d5-4a97-b9f6-a33a304ba10c"/>
				<textFieldExpression><![CDATA[$F{provincia}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="274" y="120" width="66" height="18" uuid="9c8b2d0f-142a-4645-8d0b-f14b2b4e33d7"/>
				<textFieldExpression><![CDATA[$F{cap}]]></textFieldExpression>
			</textField>
			<componentElement>
				<reportElement x="283" y="80" width="268" height="20" uuid="af26822a-b685-4bf7-bf48-fc1e371857f5">
					<property name="com.jaspersoft.studio.unit.barHeight" value="pixel"/>
					<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
					<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
				</reportElement>
				<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components"
							 xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"
							 type="Code39" drawText="false" checksumRequired="false">
					<jr:codeExpression><![CDATA[$F{codiceFiscale}]]></jr:codeExpression>
				</jr:barbecue>
			</componentElement>
			<textField>
				<reportElement x="280" y="111" width="270" height="16" uuid="486ef37e-a78c-416d-8e02-ca68560bb88d"/>
				<textElement textAlignment="Center"/>
				<textFieldExpression><![CDATA["*"+$F{codiceFiscale}+"*"]]></textFieldExpression>
			</textField>
			<line>
				<reportElement x="0" y="138" width="550" height="1" uuid="f96f04f9-c8aa-4517-ac63-bb164e606ace"/>
			</line>
			<textField>
				<reportElement x="0" y="145" width="66" height="18" uuid="dbd178d6-5e24-4cc9-87de-a26d08f002ae"/>
				<textFieldExpression><![CDATA[$F{esenzione}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="180" y="145" width="66" height="18" uuid="254c9237-25aa-45c9-b768-b8ef43941350"/>
				<textFieldExpression><![CDATA[$F{assistitoProvincia}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="290" y="145" width="66" height="18" uuid="51bbd7bb-48ef-4819-afaf-c162eb950415"/>
				<textFieldExpression><![CDATA[$F{codiceASL}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="364" y="145" width="186" height="18" uuid="bad76e0c-6dee-4b1f-a285-a2c0dfe6ceb7"/>
				<textFieldExpression><![CDATA[$F{disposizioniRegionali}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="0" y="170" width="270" height="18" uuid="ccbe7033-dee5-40bb-aa4c-fef4cb3880ce"/>
				<textFieldExpression><![CDATA[$F{tipologiaPrescrizione}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="290" y="170" width="66" height="18" uuid="27582967-d8b4-43c2-9b28-cfeb3a809c76"/>
				<textFieldExpression><![CDATA[$F{altro}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="390" y="171" width="66" height="18" uuid="7844d148-0d92-4ac0-b17c-97cfe54be725"/>
				<textFieldExpression><![CDATA[$F{priorita}]]></textFieldExpression>
			</textField>
		</band>
	</title>
	<detail>
		<band height="381" splitType="Stretch">
			<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
			<subreport>
				<reportElement stretchType="ContainerHeight" x="0" y="0" width="551" height="381"
							   uuid="0ccf626f-1294-4f9b-aeea-936d892dae92"/>
				<dataSourceExpression>
					<![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{righe})]]></dataSourceExpression>
				<subreportExpression><![CDATA["./ricetta_riga.jasper"]]></subreportExpression>
			</subreport>
		</band>
	</detail>
	<summary>
		<band height="120" splitType="Stretch">
			<textField>
				<reportElement x="0" y="80" width="545" height="14" uuid="5ca19a6d-a018-49bb-a0cb-dbe5888ed393"/>
				<textFieldExpression><![CDATA[$F{promemoria}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="0" y="40" width="260" height="14" uuid="71df866e-cbe5-4729-beec-4a7c77cdf8b7"/>
				<textFieldExpression><![CDATA[$F{codiceAutenticazione}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="290" y="40" width="260" height="14" uuid="379e434f-7615-416b-a418-c4b1891054ef"/>
				<textFieldExpression><![CDATA[$F{medicoPrescrittoreCognomeNome}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="380" y="20" width="170" height="14" uuid="d85403c5-3df2-444a-b1f6-688a42e5dd6a"/>
				<textFieldExpression><![CDATA[$F{medicoPrescrittoreCodiceFiscale}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="280" y="20" width="85" height="14" uuid="1e05a597-0f8b-4375-9a9d-3b09e7dea35c"/>
				<textFieldExpression><![CDATA[$F{dataCompilazione}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="140" y="20" width="130" height="14" uuid="ae345781-8258-474e-b48d-4b8ca7b1b9f9"/>
				<textFieldExpression><![CDATA[$F{tipoRicetta}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="0" y="20" width="130" height="14" uuid="9538bb42-5aa6-4452-af4e-842e575d94bb"/>
				<textFieldExpression><![CDATA[$F{totaleConfezioni}]]></textFieldExpression>
			</textField>
			<staticText>
				<reportElement x="0" y="60" width="550" height="17" uuid="aca2d50c-2611-41df-817e-222c56375c39"/>
				<textElement textAlignment="Center"/>
				<text>
					<![CDATA[Rilasciato ai sensi dell'art. 11, comma 16 del DL 31 mag 2010, n. 78 e dell'art.1, comma 4 del DM 2 nov 2011]]></text>
			</staticText>
			<textField>
				<reportElement x="0" y="6" width="550" height="14" uuid="3782d2ad-ae9d-4b27-87b8-793f7e6d3255"/>
				<textFieldExpression><![CDATA[$F{diagnosi}]]></textFieldExpression>
			</textField>
			<line>
				<reportElement x="0" y="102" width="544" height="1" uuid="cf889d8e-c816-4b77-80ee-daa9b2c41eb0">
					<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
				</reportElement>
			</line>
		</band>
	</summary>
</jasperReport>

And Java model

@BindType
public class JasperReport {
		
	public List<Property> property = new ArrayList<>();
}

@BindType
public class Property {
	public String content;

	@BindXml(xmlType = XmlType.ATTRIBUTE)
	public String name;

	@BindXml(xmlType = XmlType.ATTRIBUTE)
	public String value;
}

The parser read as Property also the tag at deeper lever than 1.

xml flat array is readed in a wrong way

An XML file:

<jasperReport 
        name="ricetta" pageWidth="595" pageHeight="421" columnWidth="555"
        leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" 
        uuid="dfcc67f8-27a8-4010-90a8-70d1d9f2f28d">
	<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sanita Ricetta"/>
	<property name="com.jaspersoft.studio.unit." value="pixel"/>
	<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
</jasperReport>

With a Java model:

@BindType
public class JasperReport {		
	public List<Property> property = new ArrayList<>();
}

@BindType
public class Property {
	public String content;

	@BindXml(xmlType = XmlType.ATTRIBUTE)
	public String name;

	@BindXml(xmlType = XmlType.ATTRIBUTE)
	public String value;
}

It is read as (JSON format):

{
	"property": [
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null,
		null
	]
}

Table alias must be checked

If the table name is specified by @BindSqlType, no check was done to verify that no table has the same name.

support for xml collection of element of different type

Support for xml collection of element of different type.

I need to parse an XML with an array of element of different types. Will Kripton help me?

Tests to do:

  • can not insert a type that is not specified with @BindXmlElements annotation
  • With @BindXmlElement it no allowed to use an element name used with another field
  • With @BindXmlElement it no allowed to use an element name used with another field annotated with @BindXmlElement
  • @BindXmlElement can be used only List or Set collection type fields.
  • type of the annotated @BindXmlElement element has to be a parent class of elements specified with annotations.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.