5.0 Source Code

Committing 5.0 Source Code
This commit is contained in:
2023-04-06 18:58:04 +01:00
parent 0f3ede77fa
commit 0282345603
1680 changed files with 241310 additions and 0 deletions
@@ -0,0 +1,275 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JG uniCenta
*/
public abstract class BaseSentence implements SentenceList, SentenceFind, SentenceExec {
// Funciones de bajo nivel
/**
*
* @param params
* @return
* @throws BasicException
*/
public abstract DataResultSet openExec(Object params) throws BasicException;
/**
*
* @return
* @throws BasicException
*/
public abstract DataResultSet moreResults() throws BasicException;
/**
*
* @throws BasicException
*/
public abstract void closeExec() throws BasicException;
// Funciones
/**
*
* @return
* @throws BasicException
*/
@Override
public final int exec() throws BasicException {
return exec((Object) null);
}
/**
*
* @param params
* @return
* @throws BasicException
*/
@Override
public final int exec(Object... params) throws BasicException {
return exec((Object) params);
}
/**
*
* @param params
* @return
* @throws BasicException
*/
@Override
public final int exec(Object params) throws BasicException {
DataResultSet SRS = openExec(params);
if (SRS == null) {
throw new BasicException(LocalRes.getIntString("exception.noupdatecount"));
}
int iResult = SRS.updateCount();
SRS.close();
closeExec();
return iResult;
}
/**
*
* @return
* @throws BasicException
*/
@Override
public final List list() throws BasicException {
return list((Object) null);
}
/**
*
* @param params
* @return
* @throws BasicException
*/
@Override
public final List list(Object... params) throws BasicException {
return list((Object) params);
}
/**
*
* @param params
* @return
* @throws BasicException
*/
@Override
public final List list(Object params) throws BasicException {
// En caso de error o lanza un pepinazo en forma de DataException
DataResultSet SRS = openExec(params);
List aSO = fetchAll(SRS);
SRS.close();
closeExec();
return aSO;
}
/**
*
* @param offset
* @param length
* @return
* @throws BasicException
*/
@Override
public final List listPage(int offset, int length) throws BasicException {
return listPage(null, offset, length);
}
/**
*
* @param params
* @param offset
* @param length
* @return
* @throws BasicException
*/
@Override
public final List listPage(Object params, int offset, int length) throws BasicException {
// En caso de error o lanza un pepinazo en forma de DataException
DataResultSet SRS = openExec(params);
List aSO = fetchPage(SRS, offset, length);
SRS.close();
closeExec();
return aSO;
}
/**
*
* @return
* @throws BasicException
*/
@Override
public final Object find() throws BasicException {
return find((Object) null);
}
/**
*
* @param params
* @return
* @throws BasicException
*/
@Override
public final Object find(Object... params) throws BasicException {
return find((Object) params);
}
/**
*
* @param params
* @return
* @throws BasicException
*/
@Override
public final Object find(Object params) throws BasicException {
// En caso de error o lanza un pepinazo en forma de SQLException
DataResultSet SRS = openExec(params);
Object obj = fetchOne(SRS);
SRS.close();
closeExec();
return obj;
}
// Utilidades
/**
*
* @param SRS
* @return
* @throws BasicException
*/
public final List fetchAll(DataResultSet SRS) throws BasicException {
if (SRS == null) {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
List aSO = new ArrayList();
while (SRS.next()) {
aSO.add(SRS.getCurrent());
}
return aSO;
}
// Utilidades
/**
*
* @param SRS
* @param offset
* @param length
* @return
* @throws BasicException
*/
public final List fetchPage(DataResultSet SRS, int offset, int length) throws BasicException {
if (SRS == null) {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
if (offset < 0 || length < 0) {
throw new BasicException(LocalRes.getIntString("exception.nonegativelimits"));
}
// Skip los primeros que no me importan
while (offset > 0 && SRS.next()) {
offset--;
}
// me traigo tantos como me han dicho
List aSO = new ArrayList();
if (offset == 0) {
while (length > 0 && SRS.next()) {
length--;
aSO.add(SRS.getCurrent());
}
}
return aSO;
}
/**
*
* @param SRS
* @return
* @throws BasicException
*/
public final Object fetchOne(DataResultSet SRS) throws BasicException {
if (SRS == null) {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
if (SRS.next()) {
return SRS.getCurrent();
} else {
return null;
}
}
}
@@ -0,0 +1,89 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author adrian
*/
public class BasicSentenceEnum implements SentenceEnum {
BaseSentence sent;
DataResultSet SRS;
/** Creates a new instance of AbstractSentenceEnum
* @param sent */
public BasicSentenceEnum(BaseSentence sent) {
this.sent = sent;
this.SRS = null;
}
/**
*
* @throws BasicException
*/
public void load() throws BasicException {
load(null);
}
/**
*
* @param params
* @throws BasicException
*/
public void load(Object params) throws BasicException {
SRS = sent.openExec(params);
}
/**
*
* @return
* @throws BasicException
*/
public Object getCurrent() throws BasicException {
if (SRS == null) {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
return SRS.getCurrent();
}
/**
*
* @return
* @throws BasicException
*/
public boolean next() throws BasicException {
if (SRS == null) {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
if (SRS.next()) {
return true;
} else {
SRS.close();
SRS = null;
sent.closeExec();
return false;
}
}
}
@@ -0,0 +1,345 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author JG uniCenta
*/
public abstract class BatchSentence extends BaseSentence {
/**
*
*/
protected Session m_s;
/**
*
*/
protected HashMap<String, String> m_parameters;
/** Creates a new instance of BatchSentence
* @param s */
public BatchSentence(Session s) {
m_s = s;
m_parameters = new HashMap<>();
}
/**
*
* @param name
* @param replacement
*/
public void putParameter(String name, String replacement) {
m_parameters.put(name, replacement);
}
/**
*
* @return
* @throws BasicException
*/
protected abstract Reader getReader() throws BasicException;
/**
*
*/
public class ExceptionsResultSet implements DataResultSet {
List l;
int m_iIndex;
/**
*
* @param l
*/
public ExceptionsResultSet(List l) {
this.l = l;
m_iIndex = -1;
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
@Override
public Integer getInt(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
@Override
public String getString(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
@Override
public Double getDouble(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
@Override
public Boolean getBoolean(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
@Override
public java.util.Date getTimestamp(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
//public java.io.InputStream getBinaryStream(int columnIndex) throws DataException;
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
@Override
public byte[] getBytes(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
@Override
public Object getObject(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
// public int getColumnCount() throws DataException;
/**
*
* @return
* @throws BasicException
*/
@Override
public DataField[] getDataField() throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @return
* @throws BasicException
*/
@Override
public Object getCurrent() throws BasicException {
if (m_iIndex < 0 || m_iIndex >= l.size()) {
throw new BasicException(LocalRes.getIntString("exception.outofbounds"));
} else {
return l.get(m_iIndex);
}
}
/**
*
* @return
* @throws BasicException
*/
@Override
public boolean next() throws BasicException {
return ++m_iIndex < l.size();
}
/**
*
* @throws BasicException
*/
@Override
public void close() throws BasicException {
}
/**
*
* @return
*/
@Override
public int updateCount() {
return 0;
}
}
/**
*
* @throws BasicException
*/
@Override
public final void closeExec() throws BasicException {
}
/**
*
* @return
* @throws BasicException
*/
@Override
public final DataResultSet moreResults() throws BasicException {
return null;
}
/**
*
* @param params
* @return
* @throws BasicException
*/
@Override
public DataResultSet openExec(Object params) throws BasicException {
BufferedReader br = new BufferedReader(getReader());
String sLine;
StringBuffer sSentence = new StringBuffer();
List aExceptions = new ArrayList();
try {
while ((sLine = br.readLine()) != null) {
sLine = sLine.trim();
if (!sLine.equals("") && !sLine.startsWith("--")) {
// No es un comentario ni linea vacia
if (sLine.endsWith(";")) {
// ha terminado la sentencia
sSentence.append(sLine.substring(0, sLine.length() - 1));
// File parameters
Pattern pattern = Pattern.compile("\\$(\\w+)\\{([^}]*)\\}");
Matcher matcher = pattern.matcher(sSentence.toString());
List paramlist = new ArrayList();
// Replace all occurrences of pattern in input
StringBuffer buf = new StringBuffer();
while (matcher.find()) {
if ("FILE".equals(matcher.group(1))) {
paramlist.add(ImageUtils.getBytesFromResource(matcher.group(2)));
matcher.appendReplacement(buf, "?");
} else {
String replacement = m_parameters.get(matcher.group(1));
if (replacement == null) {
matcher.appendReplacement(buf, Matcher.quoteReplacement(matcher.group(0)));
} else {
paramlist.add(replacement);
matcher.appendReplacement(buf, "?");
}
}
}
matcher.appendTail(buf);
// La disparo
try {
BaseSentence sent;
if (paramlist.isEmpty()) {
sent = new StaticSentence(m_s, buf.toString());
sent.exec();
} else {
sent = new PreparedSentence(m_s, buf.toString(), SerializerWriteBuilder.INSTANCE);
sent.exec(new VarParams(paramlist));
}
} catch (BasicException eD) {
aExceptions.add(eD);
}
sSentence = new StringBuffer();
} else {
// la sentencia continua en la linea siguiente
sSentence.append(sLine);
}
}
}
br.close();
} catch (IOException eIO) {
throw new BasicException(LocalRes.getIntString("exception.noreadfile"), eIO);
}
if (sSentence.length() > 0) {
// ha quedado una sentencia inacabada
aExceptions.add(new BasicException(LocalRes.getIntString("exception.nofinishedfile")));
}
return new ExceptionsResultSet(aExceptions);
}
private static class VarParams implements SerializableWrite {
private List l;
public VarParams(List l) {
this.l = l;
}
@Override
public void writeValues(DataWrite dp) throws BasicException {
for (int i = 0; i < l.size(); i++) {
Object v = l.get(i);
if (v instanceof String) {
dp.setString(i + 1, (String) v);
} else if (v instanceof byte[]) {
dp.setBytes(i + 1, (byte[]) l.get(i));
} else {
dp.setObject(i + 1, v);
}
}
}
}
}
@@ -0,0 +1,63 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import com.unicenta.basic.BasicException;
import java.io.UnsupportedEncodingException;
/**
*
* @author adrianromero
*/
public class BatchSentenceResource extends BatchSentence {
private String m_sResScript;
/** Creates a new instance of BatchSentenceResource
* @param s
* @param resscript */
public BatchSentenceResource(Session s, String resscript) {
super(s);
m_sResScript = resscript;
}
/**
*
* @return
* @throws BasicException
*/
protected Reader getReader() throws BasicException {
InputStream in = BatchSentenceResource.class.getResourceAsStream(m_sResScript);
if (in == null) {
throw new BasicException(LocalRes.getIntString("exception.nosentencesfile"));
} else {
try {
return new InputStreamReader(in, "UTF-8");
} catch (UnsupportedEncodingException ex) {
throw new BasicException(LocalRes.getIntString("exception.nosentencesfile"), ex);
}
}
}
}
@@ -0,0 +1,51 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import java.io.Reader;
import com.unicenta.basic.BasicException;
/**
*
* @author adrianromero
*/
public class BatchSentenceScript extends BatchSentence {
private String m_sScript;
/** Creates a new instance of BatchSentenceScript
* @param s
* @param script */
public BatchSentenceScript(Session s, String script) {
super(s);
m_sScript = script;
}
/**
*
* @return
* @throws BasicException
*/
protected Reader getReader() throws BasicException {
return new java.io.StringReader(m_sScript);
}
}
@@ -0,0 +1,63 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.pos.forms.AppConfig;
import java.io.*;
/**
*
* @author JG uniCenta
*/
public class CompanyDetails {
private String db_url;
private String db_user;
private String db_password;
private File m_config;
private Session session;
/**
*
*/
public CompanyDetails() {
AppConfig config = new AppConfig(m_config);
}
/**
*
* @param config
*/
public void loadProperties(AppConfig config) {
db_url=(config.getProperty("db.url"));
db_user=(config.getProperty("db_user"));
db_password=(config.getProperty("db.password"));
}
/**
*
* @return
*/
public String getUser() {
return db_user;
}
}
@@ -0,0 +1,42 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import java.util.Comparator;
/**
*
* @author JG uniCenta
*/
public interface ComparatorCreator {
/**
*
* @return
*/
public String[] getHeaders();
/**
*
* @param index
* @return
*/
public Comparator createComparator(int[] index);
}
@@ -0,0 +1,117 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import java.util.Comparator;
/**
*
* @author JG uniCenta
*/
public class ComparatorCreatorBasic implements ComparatorCreator {
private String[] m_sHeaders;
private Datas[] m_aDatas;
private int[] m_iAvailableIndexes;
/** Creates a new instance of ComparatorCreatorBasic
* @param sHeaders
* @param aDatas
* @param iAvailableIndexes */
public ComparatorCreatorBasic(String[] sHeaders, Datas[] aDatas, int[] iAvailableIndexes) {
m_sHeaders = sHeaders;
m_aDatas = aDatas;
m_iAvailableIndexes = iAvailableIndexes;
}
/**
*
* @param sHeaders
* @param aDatas
*/
public ComparatorCreatorBasic(String[] sHeaders, Datas[] aDatas) {
m_sHeaders = sHeaders;
m_aDatas = aDatas;
m_iAvailableIndexes = new int[aDatas.length];
for (int i = 0; i < aDatas.length; i++) {
m_iAvailableIndexes[i] = i;
}
}
/**
*
* @return
*/
public String[] getHeaders() {
String[] sTempHeaders = new String[m_iAvailableIndexes.length];
for (int i = 0; i < m_iAvailableIndexes.length; i++) {
sTempHeaders[i] = m_sHeaders[m_iAvailableIndexes[i]];
}
return sTempHeaders;
}
/**
*
* @param aiOrderBy
* @return
*/
public Comparator createComparator(int[] aiOrderBy) {
return new ComparatorBasic(aiOrderBy);
}
/**
*
*/
public class ComparatorBasic implements Comparator {
private int[] m_aiOrderBy;
/** Creates a new instance of ComparatorBasic
* @param aiOrderBy */
public ComparatorBasic(int[] aiOrderBy) {
m_aiOrderBy = aiOrderBy;
}
public int compare(Object o1, Object o2) {
if (o1 == null) {
if (o2 == null) {
return 0;
} else {
return -1;
}
} else if (o2 == null) {
return +1;
} else {
// ninguno de los dos es nulo...
Object[] ao1 = (Object[]) o1;
Object[] ao2 = (Object[]) o2;
for (int i = 0; i < m_aiOrderBy.length; i++) {
int result = m_aDatas[m_iAvailableIndexes[m_aiOrderBy[i]]].compare(ao1[m_iAvailableIndexes[m_aiOrderBy[i]]], ao2[m_iAvailableIndexes[m_aiOrderBy[i]]]);
if (result != 0) {
return result;
}
}
return 0;
}
}
}
}
@@ -0,0 +1,46 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author JG uniCenta
*/
public class DataField {
/** Creates a new instance of DataField */
public DataField() {
}
/**
*
*/
public String Name;
/**
*
*/
public int Size;
/**
*
*/
public int Type;
}
@@ -0,0 +1,121 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
import java.util.Date;
/**
*
* @author adrianromero
*/
public abstract class DataParams implements DataWrite {
/**
*
*/
protected DataWrite dw;
/**
*
* @throws BasicException
*/
public abstract void writeValues() throws BasicException;
/**
*
* @param paramIndex
* @param iValue
* @throws BasicException
*/
public void setInt(int paramIndex, Integer iValue) throws BasicException {
dw.setInt(paramIndex, iValue);
}
public void setString(int paramIndex, String sValue) throws BasicException {
dw.setString(paramIndex, sValue);
}
/**
*
* @param paramIndex
* @param dValue
* @throws BasicException
*/
public void setDouble(int paramIndex, Double dValue) throws BasicException {
dw.setDouble(paramIndex, dValue);
}
/**
*
* @param paramIndex
* @param bValue
* @throws BasicException
*/
public void setBoolean(int paramIndex, Boolean bValue) throws BasicException {
dw.setBoolean(paramIndex, bValue);
}
/**
*
* @param paramIndex
* @param dValue
* @throws BasicException
*/
public void setTimestamp(int paramIndex, Date dValue) throws BasicException {
dw.setTimestamp(paramIndex, dValue);
}
/**
*
* @param paramIndex
* @param value
* @throws BasicException
*/
public void setBytes(int paramIndex, byte[] value) throws BasicException {
dw.setBytes(paramIndex, value);
}
/**
*
* @param paramIndex
* @param value
* @throws BasicException
*/
public void setObject(int paramIndex, Object value) throws BasicException {
dw.setObject(paramIndex, value);
}
/**
*
* @return
*/
public DataWrite getDataWrite() {
return dw;
}
/**
*
* @param dw
*/
public void setDataWrite(DataWrite dw) {
this.dw = dw;
}
}
@@ -0,0 +1,96 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author adrian
*/
public interface DataRead {
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public Integer getInt(int columnIndex) throws BasicException;
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public String getString(int columnIndex) throws BasicException;
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public Double getDouble(int columnIndex) throws BasicException;
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public Boolean getBoolean(int columnIndex) throws BasicException;
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public java.util.Date getTimestamp(int columnIndex) throws BasicException;
//public java.io.InputStream getBinaryStream(int columnIndex) throws DataException;
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public byte[] getBytes(int columnIndex) throws BasicException;
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public Object getObject(int columnIndex) throws BasicException ;
// public int getColumnCount() throws DataException;
/**
*
* @return
* @throws BasicException
*/
public DataField[] getDataField() throws BasicException;
}
@@ -0,0 +1,56 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public interface DataResultSet extends DataRead {
/**
*
* @return
* @throws BasicException
*/
public Object getCurrent() throws BasicException;
/**
*
* @return
* @throws BasicException
*/
public boolean next() throws BasicException;
/**
*
* @throws BasicException
*/
public void close() throws BasicException;
/**
*
* @return
* @throws BasicException
*/
public int updateCount() throws BasicException;
}
@@ -0,0 +1,86 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author adrian
*/
public interface DataWrite {
/**
*
* @param paramIndex
* @param iValue
* @throws BasicException
*/
public void setInt(int paramIndex, Integer iValue) throws BasicException;
/**
*
* @param paramIndex
* @param sValue
* @throws BasicException
*/
public void setString(int paramIndex, String sValue) throws BasicException;
/**
*
* @param paramIndex
* @param dValue
* @throws BasicException
*/
public void setDouble(int paramIndex, Double dValue) throws BasicException;
/**
*
* @param paramIndex
* @param bValue
* @throws BasicException
*/
public void setBoolean(int paramIndex, Boolean bValue) throws BasicException;
/**
*
* @param paramIndex
* @param dValue
* @throws BasicException
*/
public void setTimestamp(int paramIndex, java.util.Date dValue) throws BasicException;
//public void setBinaryStream(int paramIndex, java.io.InputStream in, int length) throws DataException;
/**
*
* @param paramIndex
* @param value
* @throws BasicException
*/
public void setBytes(int paramIndex, byte[] value) throws BasicException;
/**
*
* @param paramIndex
* @param value
* @throws BasicException
*/
public void setObject(int paramIndex, Object value) throws BasicException;
}
@@ -0,0 +1,156 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import java.sql.Timestamp;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
/**
*
* @author adrian
*/
public class DataWriteUtils {
/** Creates a new instance of DataWriteUtils */
public DataWriteUtils() {
}
/**
*
* @param obj
* @return
*/
public static String getSQLValue(Object obj) {
if (obj == null) {
return "NULL";
} else if (obj instanceof Double) {
return getSQLValue((Double) obj);
} else if (obj instanceof Integer) {
return getSQLValue((Integer) obj);
} else if (obj instanceof Boolean) {
return getSQLValue((Boolean) obj);
} else if (obj instanceof String) {
return getSQLValue((String) obj);
} else if (obj instanceof Date) {
return getSQLValue((Date) obj);
} else {
return getSQLValue(obj.toString());
}
}
/**
*
* @param iValue
* @return
*/
public static String getSQLValue(Integer iValue) {
if (iValue == null) {
return "NULL";
} else {
return iValue.toString();
}
}
/**
*
* @param dValue
* @return
*/
public static String getSQLValue(Double dValue) {
if (dValue == null) {
return "NULL";
} else {
return dValue.toString();
}
}
/**
*
* @param bValue
* @return
*/
public static String getSQLValue(Boolean bValue) {
if (bValue == null) {
return "NULL";
} else {
return bValue.booleanValue() ? "TRUE" : "FALSE";
}
}
/**
*
* @param sValue
* @return
*/
public static String getSQLValue(String sValue) {
if (sValue == null) {
return "NULL";
} else {
return '\'' + getEscaped(sValue) + '\'';
}
}
/**
*
* @param dValue
* @return
*/
public static String getSQLValue(Date dValue) {
if (dValue == null) {
return "NULL";
} else {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = sdf.format(dValue);
return "'"+date+"'";
}
}
/**
*
* @param sValue
* @return
*/
public static String getEscaped(String sValue) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < sValue.length(); i++) {
switch (sValue.charAt(i)) {
case '\\':
sb.append("\\\\");
break;
case '\'':
sb.append("\\'");
break;
case '\n':
sb.append("\\n");
break;
case '\r':
sb.append("\\r");
break;
default:
sb.append(sValue.charAt(i));
break;
}
}
return sb.toString();
}
}
@@ -0,0 +1,388 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
/**
* @author JG uniCenta
*/
public abstract class Datas {
/**
*
*/
public final static Datas INT = new DatasINT();
/**
*
*/
public final static Datas STRING = new DatasSTRING();
/**
*
*/
public final static Datas DOUBLE = new DatasDOUBLE();
/**
*
*/
public final static Datas BOOLEAN = new DatasBOOLEAN();
/**
*
*/
public final static Datas TIMESTAMP = new DatasTIMESTAMP();
/**
*
*/
public final static Datas BYTES = new DatasBYTES();
/**
*
*/
public final static Datas IMAGE = new DatasIMAGE();
//public final static Datas INPUTSTREAM = new DatasINPUTSTREAM();
/**
*
*/
public final static Datas OBJECT = new DatasOBJECT();
/**
*
*/
public final static Datas SERIALIZABLE = new DatasSERIALIZABLE();
/**
*
*/
public final static Datas NULL = new DatasNULL();
private static DateFormat tsf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
/**
* Creates a new instance of Datas
*/
private Datas() {
}
/**
* @param dr
* @param i
* @return
* @throws BasicException
*/
public abstract Object getValue(DataRead dr, int i) throws BasicException;
/**
* @param dw
* @param i
* @param value
* @throws BasicException
*/
public abstract void setValue(DataWrite dw, int i, Object value) throws BasicException;
/**
* @return
*/
public abstract Class getClassValue();
/**
* @param value
* @return
*/
protected abstract String toStringAbstract(Object value);
/**
* @param o1
* @param o2
* @return
*/
protected abstract int compareAbstract(Object o1, Object o2);
/**
* @param value
* @return
*/
public String toString(Object value) {
if (value == null) {
return "null";
} else {
return toStringAbstract(value);
}
}
/**
* @param o1
* @param o2
* @return
*/
public int compare(Object o1, Object o2) {
if (o1 == null) {
if (o2 == null) {
return 0;
} else {
return -1;
}
} else if (o2 == null) {
return +1;
} else {
return compareAbstract(o1, o2);
}
}
private static final class DatasINT extends Datas {
public Object getValue(DataRead dr, int i) throws BasicException {
return dr.getInt(i);
}
public void setValue(DataWrite dw, int i, Object value) throws BasicException {
dw.setInt(i, (Integer) value);
}
public Class getClassValue() {
return java.lang.Integer.class;
}
protected String toStringAbstract(Object value) {
return ((Integer) value).toString();
}
protected int compareAbstract(Object o1, Object o2) {
return ((Integer) o1).compareTo((Integer) o2);
}
}
private static final class DatasSTRING extends Datas {
public Object getValue(DataRead dr, int i) throws BasicException {
return dr.getString(i);
}
public void setValue(DataWrite dw, int i, Object value) throws BasicException {
dw.setString(i, (String) value);
}
public Class getClassValue() {
return java.lang.String.class;
}
protected String toStringAbstract(Object value) {
return "\'" + DataWriteUtils.getEscaped((String) value) + "\'";
}
protected int compareAbstract(Object o1, Object o2) {
return ((String) o1).compareTo((String) o2);
}
}
private static final class DatasDOUBLE extends Datas {
public Object getValue(DataRead dr, int i) throws BasicException {
return dr.getDouble(i);
}
public void setValue(DataWrite dw, int i, Object value) throws BasicException {
dw.setDouble(i, (Double) value);
}
public Class getClassValue() {
return java.lang.Double.class;
}
protected String toStringAbstract(Object value) {
return ((Double) value).toString();
}
protected int compareAbstract(Object o1, Object o2) {
return ((Double) o1).compareTo((Double) o2);
}
}
private static final class DatasBOOLEAN extends Datas {
public Object getValue(DataRead dr, int i) throws BasicException {
return dr.getBoolean(i);
}
public void setValue(DataWrite dw, int i, Object value) throws BasicException {
dw.setBoolean(i, (Boolean) value);
}
public Class getClassValue() {
return java.lang.Boolean.class;
}
protected String toStringAbstract(Object value) {
return ((Boolean) value).toString();
}
protected int compareAbstract(Object o1, Object o2) {
return ((Boolean) o1).compareTo((Boolean) o2);
}
}
private static final class DatasTIMESTAMP extends Datas {
public Object getValue(DataRead dr, int i) throws BasicException {
return dr.getTimestamp(i);
}
public void setValue(DataWrite dw, int i, Object value) throws BasicException {
dw.setTimestamp(i, (java.util.Date) value);
}
public Class getClassValue() {
return java.util.Date.class;
}
protected String toStringAbstract(Object value) {
return tsf.format(value);
}
protected int compareAbstract(Object o1, Object o2) {
return ((java.util.Date) o1).compareTo((java.util.Date) o2);
}
}
private static final class DatasBYTES extends Datas {
public Object getValue(DataRead dr, int i) throws BasicException {
return dr.getBytes(i);
}
public void setValue(DataWrite dw, int i, Object value) throws BasicException {
dw.setBytes(i, (byte[]) value);
}
public Class getClassValue() {
return byte[].class;
}
protected String toStringAbstract(Object value) {
return "0x" + ImageUtils.bytes2hex((byte[]) value);
}
protected int compareAbstract(Object o1, Object o2) {
throw new UnsupportedOperationException();
}
}
private static final class DatasIMAGE extends Datas {
@Override
public Object getValue(DataRead dr, int i) throws BasicException {
return ImageUtils.readImage(dr.getBytes(i));
}
@Override
public void setValue(DataWrite dw, int i, Object value) throws BasicException {
dw.setBytes(i, ImageUtils.writeImage((java.awt.image.BufferedImage) value));
}
@Override
public Class getClassValue() {
return java.awt.image.BufferedImage.class;
}
@Override
protected String toStringAbstract(Object value) {
return "0x" + ImageUtils.bytes2hex(ImageUtils.writeImage((java.awt.image.BufferedImage) value));
}
@Override
protected int compareAbstract(Object o1, Object o2) {
throw new UnsupportedOperationException();
}
}
// private static final class DatasINPUTSTREAM extends Datas {
// public Object getValue(DataRead dr, int i) throws DataException {
// byte[] b = dr.getBytes(i);
// return b == null ? null : new java.io.ByteArrayInputStream(b);
// }
// public void setValue(DataWrite dw, int i, Object value) throws DataException {
// }
// }
private static final class DatasOBJECT extends Datas {
public Object getValue(DataRead dr, int i) throws BasicException {
return dr.getObject(i);
}
public void setValue(DataWrite dw, int i, Object value) throws BasicException {
dw.setObject(i, value);
}
public Class getClassValue() {
return java.lang.Object.class;
}
protected String toStringAbstract(Object value) {
return "0x" + ImageUtils.bytes2hex(ImageUtils.writeSerializable(value));
}
protected int compareAbstract(Object o1, Object o2) {
throw new UnsupportedOperationException();
}
}
private static final class DatasSERIALIZABLE extends Datas {
public Object getValue(DataRead dr, int i) throws BasicException {
return ImageUtils.readSerializable(dr.getBytes(i));
}
public void setValue(DataWrite dw, int i, Object value) throws BasicException {
dw.setBytes(i, ImageUtils.writeSerializable(value));
}
public Class getClassValue() {
return java.lang.Object.class;
}
protected String toStringAbstract(Object value) {
return "0x" + ImageUtils.bytes2hex(ImageUtils.writeSerializable(value));
}
protected int compareAbstract(Object o1, Object o2) {
throw new UnsupportedOperationException();
}
}
private static final class DatasNULL extends Datas {
public Object getValue(DataRead dr, int i) throws BasicException {
return null;
}
public void setValue(DataWrite dw, int i, Object value) throws BasicException {
// No asigno null, no asigno nada.
}
public Class getClassValue() {
return java.lang.Object.class;
}
protected String toStringAbstract(Object value) {
return "null";
}
protected int compareAbstract(Object o1, Object o2) {
throw new UnsupportedOperationException();
}
}
}
@@ -0,0 +1,34 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author JG uniCenta
*/
public interface IKeyGetter {
/**
*
* @param value
* @return
*/
public Object getKey(Object value);
}
@@ -0,0 +1,35 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author adrianromero
* Created on 27 de febrero de 2007, 22:08
*
*/
public interface IKeyed {
/**
*
* @return
*/
public Object getKey();
}
@@ -0,0 +1,34 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author JG uniCenta
*/
public interface IRenderString {
/**
*
* @param value
* @return
*/
public String getRenderString(Object value);
}
@@ -0,0 +1,38 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public interface ISQLBuilderStatic {
/**
*
* @param sw
* @param params
* @return
* @throws BasicException
*/
public String getSQL(SerializerWrite sw, Object params) throws BasicException;
}
@@ -0,0 +1,245 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;
/**
*
* @author JG uniCenta
*/
public class ImageUtils {
private static char[] HEXCHARS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
/** Creates a new instance of ImageUtils */
private ImageUtils() {
}
private static byte[] readStream(InputStream in) throws IOException {
byte[] buffer = new byte[1024];
byte[] resource = new byte[0];
int n;
while ((n = in.read(buffer)) != -1) {
byte[] b = new byte[resource.length + n];
System.arraycopy(resource, 0, b, 0, resource.length);
System.arraycopy(buffer, 0, b, resource.length, n);
resource = b;
}
return resource;
}
/**
*
* @param file
* @return
*/
public static byte[] getBytesFromResource(String file) {
InputStream in = ImageUtils.class.getResourceAsStream(file);
if (in == null) {
return null;
} else {
try {
return ImageUtils.readStream(in);
} catch (IOException e) {
return new byte[0];
} finally {
try {
in.close();
} catch (IOException e) {
}
}
}
}
/**
*
* @param file
* @return
*/
public static BufferedImage readImageFromResource(String file) {
return readImage(getBytesFromResource(file));
}
/**
*
* @param url
* @return
*/
public static BufferedImage readImage(String url) {
try {
return readImage(new URL(url));
} catch (MalformedURLException e) {
return null;
}
}
/**
*
* @param url
* @return
*/
public static BufferedImage readImage(URL url) {
InputStream in = null;
try {
URLConnection urlConnection = url.openConnection();
in = urlConnection.getInputStream();
return readImage(readStream(in));
} catch (IOException e) {
return null;
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
}
}
}
/**
*
* @param b
* @return
*/
public static BufferedImage readImage(byte[] b) {
if (b == null) {
return null;
} else {
try {
return ImageIO.read(new ByteArrayInputStream(b));
} catch(IOException e) {
return null;
}
}
}
/**
*
* @param img
* @return
*/
public static byte[] writeImage(BufferedImage img) {
if (img == null) {
return null;
} else {
try {
ByteArrayOutputStream b = new ByteArrayOutputStream();
ImageIO.write(img, "png", b);
b.flush();
b.close();
return b.toByteArray();
} catch(IOException e) {
return null;
}
}
}
/**
*
* @param b
* @return
*/
public static Object readSerializable(byte[] b) {
if (b == null) {
return null;
} else {
try {
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(b));
Object obj = in.readObject();
in.close();
return obj;
} catch (ClassNotFoundException eCNF) {
//logger.error("Cannot create lists object", eCNF);
return null;
} catch (IOException eIO) {
//logger.error("Cannot load lists file", eIO);
return null;
}
}
}
/**
*
* @param o
* @return
*/
public static byte[] writeSerializable(Object o) {
if (o == null) {
return null;
} else {
try {
ByteArrayOutputStream b = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(b);
out.writeObject(o);
out.flush();
out.close();
return b.toByteArray();
} catch (IOException eIO) {
eIO.printStackTrace();
return null;
}
}
}
/**
*
* @param b
* @return
*/
public static Properties readProperties(byte b[]) {
Properties prop = new Properties();
try {
if (b != null) {
prop.loadFromXML(new ByteArrayInputStream(b));
}
} catch (IOException e) {
}
return prop;
}
/**
*
* @param binput
* @return
*/
public static String bytes2hex(byte[] binput) {
StringBuilder s = new StringBuilder(binput.length *2);
for (int i = 0; i < binput.length; i++) {
byte b = binput[i];
s.append(HEXCHARS[(b & 0xF0) >> 4]);
s.append(HEXCHARS[b & 0x0F]);
}
return s.toString();
}
}
@@ -0,0 +1,62 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author adrian
*/
public class ImportSentence extends BaseSentence {
/** Creates a new instance of ImportSentence */
public ImportSentence() {
}
/**
*
* @throws BasicException
*/
@Override
public void closeExec() throws BasicException {
}
/**
*
* @return
* @throws BasicException
*/
@Override
public DataResultSet moreResults() throws BasicException {
return null;
}
/**
*
* @param params
* @return
* @throws BasicException
*/
@Override
public DataResultSet openExec(Object params) throws BasicException {
return null;
}
}
@@ -0,0 +1,236 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
import java.sql.*;
/**
*
* @author JG uniCenta
*/
public abstract class JDBCSentence extends BaseSentence {
// Conexion
// protected Connection m_c;
/**
*
*/
protected Session session;
/** Creates a new instance of BaseSentence
* @param session */
public JDBCSentence(Session session) {
super();
this.session = session;
}
/**
*
*/
protected static final class JDBCDataResultSet implements DataResultSet {
private ResultSet m_rs;
private SerializerRead m_serread;
// private int m_iColumnCount;
/**
*
* @param rs
* @param serread
*/
public JDBCDataResultSet(ResultSet rs, SerializerRead serread) {
m_rs = rs;
m_serread = serread;
// m_iColumnCount = -1;
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public Integer getInt(int columnIndex) throws BasicException {
try {
int iValue = m_rs.getInt(columnIndex);
return m_rs.wasNull() ? null : new Integer(iValue);
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public String getString(int columnIndex) throws BasicException {
try {
return m_rs.getString(columnIndex);
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public Double getDouble(int columnIndex) throws BasicException {
try {
double dValue = m_rs.getDouble(columnIndex);
return m_rs.wasNull() ? null : new Double(dValue);
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public Boolean getBoolean(int columnIndex) throws BasicException {
try {
boolean bValue = m_rs.getBoolean(columnIndex);
return m_rs.wasNull() ? null : new Boolean(bValue);
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public java.util.Date getTimestamp(int columnIndex) throws BasicException {
try {
java.sql.Timestamp ts = m_rs.getTimestamp(columnIndex);
return ts == null ? null : new java.util.Date(ts.getTime());
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public byte[] getBytes(int columnIndex) throws BasicException {
try {
return m_rs.getBytes(columnIndex);
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public Object getObject(int columnIndex) throws BasicException {
try {
return m_rs.getObject(columnIndex);
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
*
* @return
* @throws BasicException
*/
public DataField[] getDataField() throws BasicException {
try {
ResultSetMetaData md = m_rs.getMetaData();
DataField[] df = new DataField[md.getColumnCount()];
for (int i = 0; i < df.length; i++) {
df[i] = new DataField();
df[i].Name = md.getColumnName(i + 1);
df[i].Size = md.getColumnDisplaySize(i + 1);
df[i].Type = md.getColumnType(i + 1);
}
return df;
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
*
* @return
* @throws BasicException
*/
@Override
public Object getCurrent() throws BasicException {
return m_serread.readValues(this);
}
/**
*
* @return
* @throws BasicException
*/
@Override
public boolean next() throws BasicException {
try {
return m_rs.next();
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
*
* @throws BasicException
*/
@Override
public void close() throws BasicException {
try {
m_rs.close();
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
*
* @return
* @throws BasicException
*/
@Override
public int updateCount() throws BasicException {
return -1; // es decir somos datos.
}
}
}
@@ -0,0 +1,54 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author adrian
*/
public class KeyGetterBasic implements IKeyGetter {
private int [] m_aElems;
/** Creates a new instance of KeyGetterBasic
* @param aElems */
public KeyGetterBasic(int[] aElems) {
m_aElems = aElems;
}
/**
*
* @param value
* @return
*/
public Object getKey(Object value) {
if (value == null) {
return null;
} else {
Object[] avalue = (Object []) value;
Object[] akey = new Object[m_aElems.length];
for (int i = 0; i < m_aElems.length; i++) {
akey[i] = avalue[m_aElems[i]];
}
return akey;
}
}
}
@@ -0,0 +1,51 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author adrianromero
* Created on 27 de febrero de 2007, 22:09
*
*/
public class KeyGetterBuilder implements IKeyGetter {
/**
*
*/
public final static IKeyGetter INSTANCE = new KeyGetterBuilder();
/** Creates a new instance of KeyGetterBuilder */
public KeyGetterBuilder() {
}
/**
*
* @param value
* @return
*/
@Override
public Object getKey(Object value) {
return (value == null)
? null
: ((IKeyed) value).getKey();
}
}
@@ -0,0 +1,50 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author adrian
*/
public class KeyGetterFirst implements IKeyGetter {
private final int [] m_aElems;
/** Creates a new instance of KeyGetterBasic
* @param aElems */
public KeyGetterFirst(int[] aElems) {
m_aElems = aElems;
}
/**
*
* @param value
* @return
*/
@Override
public Object getKey(Object value) {
if (value == null) {
return null;
} else {
Object[] avalue = (Object []) value;
return avalue[m_aElems[0]];
}
}
}
@@ -0,0 +1,51 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import java.util.MissingResourceException;
import com.unicenta.beans.LocaleResources;
/**
*
* @author JG uniCenta
*/
public class LocalRes {
// private static ResourceBundle m_Intl;
private static LocaleResources m_resources;
static {
m_resources = new LocaleResources();
m_resources.addBundleName("data_messages");
}
/** Creates a new instance of LocalRes */
private LocalRes() {
}
/**
*
* @param sKey
* @return
*/
public static String getIntString(String sKey) {
return m_resources.getString(sKey);
}
}
@@ -0,0 +1,212 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import java.sql.*;
import java.util.*;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class MetaSentence extends JDBCSentence {
private String m_sSentence;
/**
*
*/
protected SerializerRead m_SerRead = null;
/**
*
*/
protected SerializerWrite m_SerWrite = null;
/** Creates a new instance of MetaDataSentence
* @param s
* @param sSentence
* @param serwrite
* @param serread */
public MetaSentence(Session s, String sSentence, SerializerWrite serwrite, SerializerRead serread) {
super(s);
m_sSentence = sSentence;
m_SerWrite = serwrite;
m_SerRead = serread;
}
/**
*
* @param s
* @param sSentence
* @param serread
*/
public MetaSentence(Session s, String sSentence, SerializerRead serread) {
this(s, sSentence, null, serread);
}
private static class MetaParameter implements DataWrite {
private ArrayList m_aParams;
/** Creates a new instance of MetaParameter */
public MetaParameter() {
m_aParams = new ArrayList();
}
public void setDouble(int paramIndex, Double dValue) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.noparamtype"));
}
public void setBoolean(int paramIndex, Boolean bValue) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.noparamtype"));
}
public void setInt(int paramIndex, Integer iValue) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.noparamtype"));
}
public void setString(int paramIndex, String sValue) throws BasicException {
ensurePlace(paramIndex - 1);
m_aParams.set(paramIndex - 1, sValue);
}
public void setTimestamp(int paramIndex, java.util.Date dValue) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.noparamtype"));
}
// public void setBinaryStream(int paramIndex, java.io.InputStream in, int length) throws DataException {
// throw new DataException("Param type not allowed");
// }
public void setBytes(int paramIndex, byte[] value) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.noparamtype"));
}
public void setObject(int paramIndex, Object value) throws BasicException {
setString(paramIndex, (value == null) ? null : value.toString());
}
public String getString(int index) {
return (String) m_aParams.get(index);
}
private void ensurePlace(int i) {
m_aParams.ensureCapacity(i);
while (i >= m_aParams.size()){
m_aParams.add(null);
}
}
}
/**
*
* @param params
* @return
* @throws BasicException
*/
public DataResultSet openExec(Object params) throws BasicException {
closeExec();
try {
DatabaseMetaData db = session.getConnection().getMetaData();
MetaParameter mp = new MetaParameter();
if (params != null) {
// si m_SerWrite fuera null deberiamos cascar
m_SerWrite.writeValues(mp, params);
}
// Catalogs Has Schemas Has Objects
// Lo generico de la base de datos
if ("getCatalogs".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getCatalogs(), m_SerRead);
} else if ("getSchemas".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getSchemas(), m_SerRead);
} else if ("getTableTypes".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getTableTypes(), m_SerRead);
} else if ("getTypeInfo".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getTypeInfo(), m_SerRead);
// Los objetos por catalogo, esquema
// Los tipos definidos por usuario
} else if ("getUDTs".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getUDTs(mp.getString(0), mp.getString(1), null, null), m_SerRead);
} else if ("getSuperTypes".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getSuperTypes(mp.getString(0), mp.getString(1), mp.getString(2)), m_SerRead);
// Los atributos
} else if ("getAttributes".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getAttributes(mp.getString(0), mp.getString(1), null, null), m_SerRead);
// Las Tablas y sus objetos relacionados
} else if ("getTables".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getTables(mp.getString(0), mp.getString(1), null, null), m_SerRead);
} else if ("getSuperTables".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getSuperTables(mp.getString(0), mp.getString(1), mp.getString(2)), m_SerRead);
} else if ("getTablePrivileges".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getTablePrivileges(mp.getString(0), mp.getString(1), mp.getString(2)), m_SerRead);
} else if ("getBestRowIdentifier".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getBestRowIdentifier(mp.getString(0), mp.getString(1), mp.getString(2), 0, true), m_SerRead);
} else if ("getPrimaryKeys".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getPrimaryKeys(mp.getString(0), mp.getString(1), mp.getString(2)), m_SerRead);
} else if ("getColumnPrivileges".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getColumnPrivileges(mp.getString(0), mp.getString(1), mp.getString(2), null), m_SerRead);
} else if ("getColumns".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getColumns(mp.getString(0), mp.getString(1), mp.getString(2), null), m_SerRead);
} else if ("getVersionColumns".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getVersionColumns(mp.getString(0), mp.getString(1), mp.getString(2)), m_SerRead);
} else if ("getIndexInfo".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getIndexInfo(mp.getString(0), mp.getString(1), mp.getString(2), false, false), m_SerRead);
} else if ("getExportedKeys".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getExportedKeys(mp.getString(0), mp.getString(1), mp.getString(2)), m_SerRead);
} else if ("getImportedKeys".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getImportedKeys(mp.getString(0), mp.getString(1), mp.getString(2)), m_SerRead);
} else if ("getCrossReference".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getCrossReference(mp.getString(0), mp.getString(1), mp.getString(2), null, null, null), m_SerRead);
// Los procedimientos y sus objetos relacionados
} else if ("getProcedures".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getProcedures(mp.getString(0), mp.getString(1), null), m_SerRead);
} else if ("getProcedureColumns".equals(m_sSentence)) {
return new JDBCDataResultSet(db.getProcedureColumns(mp.getString(0), mp.getString(1), mp.getString(2), null), m_SerRead);
} else {
return null;
}
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
*
* @throws BasicException
*/
public void closeExec() throws BasicException {
}
/**
*
* @return
* @throws BasicException
*/
public DataResultSet moreResults() throws BasicException {
return null;
}
}
@@ -0,0 +1,136 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import java.util.*;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class NormalBuilder implements ISQLBuilderStatic {
public String sentence;
/** Creates a new instance of NormalBuilder
* @param sSentence */
public NormalBuilder(String sSentence) {
sentence = sSentence;
}
/**
*
* @param write
* @param params
* @return
* @throws BasicException
*/
@Override
public String getSQL(SerializerWrite write, Object params) throws BasicException {
NormalParameter normalParameter = new NormalParameter(sentence);
if (write != null) {
write.writeValues(normalParameter, params);
}
return normalParameter.getSentence();
}
private static class NormalParameter implements DataWrite {
private String m_sSentence;
private ArrayList m_aParams; // of String
public NormalParameter(String sSentence) {
m_sSentence = sSentence;
m_aParams = new ArrayList();
}
@Override
public void setDouble(int paramIndex, Double dValue) throws BasicException {
ensurePlace(paramIndex - 1);
m_aParams.set(paramIndex - 1, DataWriteUtils.getSQLValue(dValue));
}
@Override
public void setBoolean(int paramIndex, Boolean bValue) throws BasicException {
ensurePlace(paramIndex - 1);
m_aParams.set(paramIndex - 1, DataWriteUtils.getSQLValue(bValue));
}
@Override
public void setInt(int paramIndex, Integer iValue) throws BasicException {
ensurePlace(paramIndex - 1);
m_aParams.set(paramIndex - 1, DataWriteUtils.getSQLValue(iValue));
}
@Override
public void setString(int paramIndex, String sValue) throws BasicException {
ensurePlace(paramIndex - 1);
m_aParams.set(paramIndex - 1, DataWriteUtils.getSQLValue(sValue));
}
@Override
public void setTimestamp(int paramIndex, java.util.Date dValue) throws BasicException {
ensurePlace(paramIndex - 1);
m_aParams.set(paramIndex - 1, DataWriteUtils.getSQLValue(dValue));
}
// public void setBinaryStream(int paramIndex, java.io.InputStream in, int length) throws DataException{
// throw new DataException("Param type not allowed");
// }
@Override
public void setBytes(int paramIndex, byte[] value) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.noparamtype"));
}
@Override
public void setObject(int paramIndex, Object value) throws BasicException {
ensurePlace(paramIndex - 1);
m_aParams.set(paramIndex - 1, DataWriteUtils.getSQLValue(value));
}
private void ensurePlace(int i) {
m_aParams.ensureCapacity(i);
while (i >= m_aParams.size()){
m_aParams.add(null);
}
}
public String getSentence() {
StringBuilder sNewSentence = new StringBuilder();
int iCount = 0;
int iPos;
int iLast = 0;
while ((iPos = m_sSentence.indexOf('?', iLast)) > 0) {
sNewSentence.append(m_sSentence.substring(iLast, iPos));
if (iCount < m_aParams.size() && m_aParams.get(iCount) != null) {
// el valor que viene
sNewSentence.append(m_aParams.get(iCount));
} else {
// nulo
sNewSentence.append(DataWriteUtils.getSQLValue((Object) null));
}
iCount++;
iLast = iPos + 1;
}
sNewSentence.append(m_sSentence.substring(iLast));
return sNewSentence.toString(); // sustituida
}
}
}
@@ -0,0 +1,250 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
import lombok.extern.slf4j.Slf4j;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
/**
*
* @author adrianromero
*/
@Slf4j
public class PreparedSentence extends JDBCSentence {
private String m_sentence;
/**
*
*/
protected SerializerWrite m_SerWrite = null;
/**
*
*/
protected SerializerRead m_SerRead = null;
// Estado
private PreparedStatement m_Stmt;
/**
*
* @param s
* @param sentence
* @param serwrite
* @param serread
*/
public PreparedSentence(Session s, String sentence, SerializerWrite serwrite, SerializerRead serread) {
super(s);
m_sentence = sentence;
m_SerWrite = serwrite;
m_SerRead = serread;
m_Stmt = null;
}
/**
*
* @param s
* @param sentence
* @param serwrite
*/
public PreparedSentence(Session s, String sentence, SerializerWrite serwrite) {
this(s, sentence, serwrite, null);
}
/**
*
* @param s
* @param sentence
*/
public PreparedSentence(Session s, String sentence) {
this(s, sentence, null, null);
}
private static final class PreparedSentencePars implements DataWrite {
private PreparedStatement m_ps;
/** Creates a new instance of SQLParameter */
PreparedSentencePars(PreparedStatement ps) {
m_ps = ps;
}
@Override
public void setInt(int paramIndex, Integer iValue) throws BasicException {
try {
m_ps.setObject(paramIndex, iValue, Types.INTEGER);
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
@Override
public void setString(int paramIndex, String sValue) throws BasicException {
try {
m_ps.setString(paramIndex, sValue);
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
@Override
public void setDouble(int paramIndex, Double dValue) throws BasicException {
try {
m_ps.setObject(paramIndex, dValue, Types.DOUBLE);
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
@Override
public void setBoolean(int paramIndex, Boolean bValue) throws BasicException {
try {
if (bValue == null) {
m_ps.setObject(paramIndex, null);
} else {
m_ps.setBoolean(paramIndex, bValue.booleanValue());
}
// m_ps.setObject(paramIndex, bValue, Types.BOOLEAN);
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
@Override
public void setTimestamp(int paramIndex, java.util.Date dValue) throws BasicException {
try {
m_ps.setObject(paramIndex, dValue == null ? null : new Timestamp(dValue.getTime()), Types.TIMESTAMP);
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
// public void setBinaryStream(int paramIndex, java.io.InputStream in, int length) throws DataException {
// try {
// m_ps.setBinaryStream(paramIndex, in, length);
// } catch (SQLException eSQL) {
// throw new DataException(eSQL);
// }
// }
@Override
public void setBytes(int paramIndex, byte[] value) throws BasicException {
try {
m_ps.setBytes(paramIndex, value);
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
@Override
public void setObject(int paramIndex, Object value) throws BasicException {
try {
m_ps.setObject(paramIndex, value);
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
}
/**
*
* @param params
* @return
* @throws BasicException
*/
@Override
public DataResultSet openExec(Object params) throws BasicException {
// true -> un resultset
// false -> un updatecount (si -1 entonces se acabo)
closeExec();
try {
log.debug("Executing prepared SQL: {}", m_sentence);
m_Stmt = session.getConnection().prepareStatement(m_sentence);
if (m_SerWrite != null) {
// si m_SerWrite fuera null deberiamos cascar.
PreparedSentencePars preparedSentencePars = new PreparedSentencePars(m_Stmt);
m_SerWrite.writeValues(preparedSentencePars, params);
}
if (m_Stmt.execute()) {
return new JDBCDataResultSet(m_Stmt.getResultSet(), m_SerRead);
} else {
int iUC = m_Stmt.getUpdateCount();
if (iUC < 0) {
return null;
} else {
return new SentenceUpdateResultSet(iUC);
}
}
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
*
* @return
* @throws BasicException
*/
@Override
public final DataResultSet moreResults() throws BasicException {
// true -> un resultset
// false -> un updatecount (si -1 entonces se acabo)
try {
if (m_Stmt.getMoreResults()){
// tenemos resultset
return new JDBCDataResultSet(m_Stmt.getResultSet(), m_SerRead);
} else {
// tenemos updatecount o si devuelve -1 ya no hay mas
int iUC = m_Stmt.getUpdateCount();
if (iUC < 0) {
return null;
} else {
return new SentenceUpdateResultSet(iUC);
}
}
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
*
* @throws BasicException
*/
@Override
public final void closeExec() throws BasicException {
if (m_Stmt != null) {
try {
m_Stmt.close();
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
} finally {
m_Stmt = null;
}
}
}
}
@@ -0,0 +1,201 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author adrian
*/
public class QBFBuilder implements ISQLBuilderStatic {
private final String m_sSentNullFilter; // la sentencia que se devuelve cuando el filtro es vacio
private final String m_sSentBeginPart; // La sentencia que se devuelve es m_sSentBeginPart + ( filtro ) + m_sSentEndPart
private final String m_sSentEndPart;
private final String[] m_asFindFields;
// /** Creates a new instance of QBFBuilder */
// public QBFBuilder(TableDefinition tb, String[] asFindFields) {
// StringBuilder sent = new StringBuilder();
// sent.append("select ");
// for (int i = 0; i < tb.getFields().length; i ++) {
// if (i > 0) {
// sent.append(", ");
// }
// sent.append(tb.getFields()[i]);
// }
// sent.append(" from ");
// sent.append(tb.getTableName());
// m_sSentNullFilter = sent.toString();
// sent.append(" where ");
// m_sSentBeginPart = sent.toString();
// m_sSentEndPart = "";
// m_asFindFields = asFindFields;
// }
/**
*
* @param sSentence
* @param asFindFields
*/
public QBFBuilder(String sSentence, String[] asFindFields) {
int iPos = sSentence.indexOf("?(QBF_FILTER)");
if (iPos < 0) {
m_sSentBeginPart = sSentence;
m_sSentEndPart = "";
m_sSentNullFilter = sSentence;
} else {
m_sSentBeginPart = sSentence.substring(0, iPos);
m_sSentEndPart = sSentence.substring(iPos + 13);
m_sSentNullFilter = m_sSentBeginPart + "(1=1)" + m_sSentEndPart;
}
m_asFindFields = asFindFields;
}
/**
*
* @param sw
* @param params
* @return
* @throws BasicException
*/
@Override
public String getSQL(SerializerWrite sw, Object params) throws BasicException {
QBFParameter mydw = new QBFParameter(m_asFindFields);
if (sw == null || params == null) {
return m_sSentNullFilter;
} else {
sw.writeValues(mydw, params);
String sFilter = mydw.getFilter();
if (sFilter.length() == 0) {
return m_sSentNullFilter; // no hay filtro
} else {
return m_sSentBeginPart + "(" + sFilter + ")" + m_sSentEndPart; // incluimos el filtro
}
}
}
private static class QBFParameter implements DataWrite {
private final String[] m_asFindFields;
private final QBFCompareEnum[] m_aiCondFields;
private final String[] m_aParams;
public QBFParameter(String[] asFindFields) {
m_asFindFields = asFindFields;
m_aiCondFields = new QBFCompareEnum[asFindFields.length];
m_aParams = new String[asFindFields.length];
for( int i = 0; i < m_aParams.length; i++) {
m_aParams[i] = DataWriteUtils.getSQLValue((Object) null);
}
}
@Override
public void setDouble(int paramIndex, Double dValue) throws BasicException {
if ((paramIndex - 1) % 2 == 0) {
throw new BasicException(LocalRes.getIntString("exception.nocompare"));
} else {
m_aParams[(paramIndex - 1) / 2] = DataWriteUtils.getSQLValue(dValue);
}
}
@Override
public void setBoolean(int paramIndex, Boolean bValue) throws BasicException {
if ((paramIndex - 1) % 2 == 0) {
throw new BasicException(LocalRes.getIntString("exception.nocompare"));
} else {
m_aParams[(paramIndex - 1) / 2] = DataWriteUtils.getSQLValue(bValue);
}
}
@Override
public void setInt(int paramIndex, Integer iValue) throws BasicException {
if ((paramIndex - 1) % 2 == 0) {
throw new BasicException(LocalRes.getIntString("exception.nocompare"));
} else {
m_aParams[(paramIndex - 1) / 2] = DataWriteUtils.getSQLValue(iValue);
}
}
@Override
public void setString(int paramIndex, String sValue) throws BasicException {
if ((paramIndex - 1) % 2 == 0) {
throw new BasicException(LocalRes.getIntString("exception.nocompare"));
} else {
m_aParams[(paramIndex - 1) / 2] = DataWriteUtils.getSQLValue(sValue);
}
}
@Override
public void setTimestamp(int paramIndex, java.util.Date dValue) throws BasicException {
if ((paramIndex - 1) % 2 == 0) {
throw new BasicException(LocalRes.getIntString("exception.nocompare"));
} else {
m_aParams[(paramIndex - 1) / 2] = DataWriteUtils.getSQLValue(dValue);
}
}
// public void setBinaryStream(int paramIndex, java.io.InputStream in, int length) throws DataException{
// if ((paramIndex - 1) % 2 == 0) {
// throw new DataException("Expected comparator for QBF");
// } else {
// throw new DataException("Param type not allowed");
// }
// }
@Override
public void setBytes(int paramIndex, byte[] value) throws BasicException {
if ((paramIndex - 1) % 2 == 0) {
throw new BasicException(LocalRes.getIntString("exception.nocompare"));
} else {
throw new BasicException("Param type not allowed");
}
}
@Override
public void setObject(int paramIndex, Object value) throws BasicException {
if ((paramIndex - 1) % 2 == 0) {
if (value instanceof QBFCompareEnum) {
m_aiCondFields[(paramIndex - 1) / 2] = (QBFCompareEnum) value;
} else {
throw new BasicException(LocalRes.getIntString("exception.nocompare"));
}
} else {
m_aParams[(paramIndex - 1) / 2] = DataWriteUtils.getSQLValue(value);
}
}
public String getFilter() {
// El retorno debe ser siempre una expresion valida puesto que no se donde sera insertada.
StringBuilder sFilter = new StringBuilder();
String sItem;
for (int i = 0; i < m_asFindFields.length; i ++) {
sItem = m_aiCondFields[i].getExpression(m_asFindFields[i], m_aParams[i]);
if (sItem != null) {
if (sFilter.length() > 0) {
sFilter.append(" AND ");
}
sFilter.append(sItem);
}
}
return sFilter.toString();
}
}
}
@@ -0,0 +1,140 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author adrian
*/
public abstract class QBFCompareEnum {
/**
*
*/
public final static QBFCompareEnum COMP_NONE = new QBFCompareEnum(0, "qbf.none") {
@Override
public String getExpression(String sField, String sSQLValue) { return null; }
};
/**
*
*/
public final static QBFCompareEnum COMP_ISNULL = new QBFCompareEnum(1, "qbf.null") {
@Override
public String getExpression(String sField, String sSQLValue) { return sField + " IS NULL"; }
};
/**
*
*/
public final static QBFCompareEnum COMP_ISNOTNULL = new QBFCompareEnum(2, "qbf.notnull") {
@Override
public String getExpression(String sField, String sSQLValue) { return sField + " IS NOT NULL"; }
};
/**
*
*/
public final static QBFCompareEnum COMP_RE = new QBFCompareEnum(3, "qbf.re") {
@Override
public String getExpression(String sField, String sSQLValue) { return sField + " LIKE " + sSQLValue; }
};
/**
*
*/
public final static QBFCompareEnum COMP_EQUALS = new QBFCompareEnum(3, "qbf.equals") {
@Override
public String getExpression(String sField, String sSQLValue) { return sField + " = " + sSQLValue; }
};
/**
*
*/
public final static QBFCompareEnum COMP_DISTINCT = new QBFCompareEnum(4, "qbf.distinct") {
@Override
public String getExpression(String sField, String sSQLValue) { return sField + " <> " + sSQLValue; }
};
/**
*
*/
public final static QBFCompareEnum COMP_GREATER = new QBFCompareEnum(5, "qbf.greater") {
@Override
public String getExpression(String sField, String sSQLValue) { return sField + " > " + sSQLValue; }
};
/**
*
*/
public final static QBFCompareEnum COMP_LESS = new QBFCompareEnum(6, "qbf.less") {
@Override
public String getExpression(String sField, String sSQLValue) { return sField + " < " + sSQLValue; }
};
/**
*
*/
public final static QBFCompareEnum COMP_GREATEROREQUALS = new QBFCompareEnum(7, "qbf.greaterequals") {
@Override
public String getExpression(String sField, String sSQLValue) { return sField + " >= " + sSQLValue; }
};
/**
*
*/
public final static QBFCompareEnum COMP_LESSOREQUALS = new QBFCompareEnum(8, "qbf.lessequals") {
@Override
public String getExpression(String sField, String sSQLValue) { return sField + " <= " + sSQLValue; }
};
// public final static QBFCompareEnum COMP_STARTSWITH = new QBFCompareEnum(9, "qbf.startswith") {
// public String getExpression(String sField, String sSQLValue) { return sField + " LIKE " ... + sSQLValue; }
// };
// public final static int COMP_ENDSWITH = 12;
// public final static int COMP_CONTAINS = 13;
private final int m_iValue;
private final String m_sKey;
private QBFCompareEnum(int iValue, String sKey) {
m_iValue = iValue;
m_sKey = sKey;
}
/**
*
* @return
*/
public int getCompareInt() {
return m_iValue;
}
@Override
public String toString() {
return LocalRes.getIntString(m_sKey);
}
/**
*
* @param sField
* @param sSQLValue
* @return
*/
public abstract String getExpression(String sField, String sSQLValue);
}
@@ -0,0 +1,65 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.format.Formats;
/**
*
* @author adrian
*/
public class RenderStringBasic implements IRenderString {
private Formats[] m_aFormats;
private int[] m_aiIndex;
/** Creates a new instance of StringnizerBasic
* @param fmts
* @param aiIndex */
public RenderStringBasic(Formats[] fmts, int[] aiIndex) {
m_aFormats = fmts;
m_aiIndex = aiIndex;
}
/**
*
* @param value
* @return
*/
public String getRenderString(Object value) {
if (value == null) {
return null;
} else {
Object [] avalue = (Object[]) value;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < m_aiIndex.length; i++) {
if (i > 0) {
sb.append(" - ");
}
sb.append(m_aFormats[m_aiIndex[i]].formatValue(avalue[m_aiIndex[i]]));
}
return sb.toString();
}
}
}
@@ -0,0 +1,56 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public interface SentenceEnum {
/**
*
* @throws BasicException
*/
public void load() throws BasicException;
/**
*
* @param params
* @throws BasicException
*/
public void load(Object params) throws BasicException;
/**
*
* @return
* @throws BasicException
*/
public Object getCurrent() throws BasicException;
/**
*
* @return
* @throws BasicException
*/
public boolean next() throws BasicException;
}
@@ -0,0 +1,52 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public interface SentenceExec {
/**
*
* @return
* @throws BasicException
*/
public int exec() throws BasicException;
/**
*
* @param params
* @return
* @throws BasicException
*/
public int exec(Object params) throws BasicException;
/**
*
* @param params
* @return
* @throws BasicException
*/
public int exec(Object... params) throws BasicException;
}
@@ -0,0 +1,56 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public abstract class SentenceExecAdapter implements SentenceExec {
/**
*
* @return
* @throws BasicException
*/
public int exec() throws BasicException {
return exec((Object) null);
}
/**
*
* @param params
* @return
* @throws BasicException
*/
public int exec(Object... params) throws BasicException {
return exec((Object) params);
}
/**
*
* @param params
* @return
* @throws BasicException
*/
public abstract int exec(Object params) throws BasicException;
}
@@ -0,0 +1,86 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author adrianromero
* Created on February 6, 2007, 4:06 PM
*
*/
public abstract class SentenceExecTransaction implements SentenceExec {
private Session m_s;
/**
*
* @param s
*/
public SentenceExecTransaction(Session s) {
m_s = s;
}
/**
*
* @return
* @throws BasicException
*/
public final int exec() throws BasicException {
return exec((Object) null);
}
/**
*
* @param params
* @return
* @throws BasicException
*/
public final int exec(Object... params) throws BasicException {
return exec((Object) params);
}
/**
*
* @param params
* @return
* @throws BasicException
*/
public final int exec(final Object params) throws BasicException {
Transaction<Integer> t = new Transaction<Integer>(m_s) {
public Integer transact() throws BasicException{
return execInTransaction(params);
}
};
return t.execute();
}
/**
*
* @param params
* @return
* @throws BasicException
*/
protected abstract int execInTransaction(Object params) throws BasicException;
}
@@ -0,0 +1,52 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public interface SentenceFind {
/**
*
* @return
* @throws BasicException
*/
public Object find() throws BasicException;
/**
*
* @param params
* @return
* @throws BasicException
*/
public Object find(Object params) throws BasicException;
/**
*
* @param params
* @return
* @throws BasicException
*/
public Object find(Object... params) throws BasicException;
}
@@ -0,0 +1,72 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
import java.util.List;
/**
*
* @author JG uniCenta
*/
public interface SentenceList {
/**
*
* @return
* @throws BasicException
*/
public List list() throws BasicException;
/**
*
* @param params
* @return
* @throws BasicException
*/
public List list(Object... params) throws BasicException;
/**
*
* @param params
* @return
* @throws BasicException
*/
public List list(Object params) throws BasicException;
/**
*
* @param offset
* @param length
* @return
* @throws BasicException
*/
public List listPage(int offset, int length) throws BasicException;
/**
*
* @param params
* @param offset
* @param length
* @return
* @throws BasicException
*/
public List listPage(Object params, int offset, int length) throws BasicException;
}
@@ -0,0 +1,154 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author adrian
*/
public class SentenceUpdateResultSet implements DataResultSet {
private int m_iUpdateCount;
/** Creates a new instance of UpdateResultSet
* @param iUpdateCount */
public SentenceUpdateResultSet(int iUpdateCount) {
m_iUpdateCount = iUpdateCount;
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public Integer getInt(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public String getString(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public Double getDouble(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public Boolean getBoolean(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public java.util.Date getTimestamp(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
//public java.io.InputStream getBinaryStream(int columnIndex) throws DataException;
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public byte[] getBytes(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @param columnIndex
* @return
* @throws BasicException
*/
public Object getObject(int columnIndex) throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
// public int getColumnCount() throws DataException;
/**
*
* @return
* @throws BasicException
*/
public DataField[] getDataField() throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @return
* @throws BasicException
*/
public Object getCurrent() throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @return
* @throws BasicException
*/
public boolean next() throws BasicException {
throw new BasicException(LocalRes.getIntString("exception.nodataset"));
}
/**
*
* @throws BasicException
*/
public void close() throws BasicException {
}
/**
*
* @return
* @throws BasicException
*/
public int updateCount() throws BasicException {
return m_iUpdateCount;
}
}
@@ -0,0 +1,75 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SequenceForDerby extends BaseSentence {
private BaseSentence sent1;
private BaseSentence sent2;
/** Creates a new instance of SequenceForMySQL
* @param s
* @param sSeqTable */
public SequenceForDerby(Session s, String sSeqTable) {
sent1 = new StaticSentence(s, "UPDATE " + sSeqTable + " SET ID = (SELECT ID FROM "+ sSeqTable +")+1 ");
sent2 = new StaticSentence(s, "SELECT ID from PICKUP_NUMBER", null, SerializerReadInteger.INSTANCE);
}
// Funciones de bajo nivel
/**
*
* @param params
* @return
* @throws BasicException
*/
@Override
public DataResultSet openExec(Object params) throws BasicException {
sent1.exec();
return sent2.openExec(null);
}
/**
*
* @return
* @throws BasicException
*/
@Override
public DataResultSet moreResults() throws BasicException {
return sent2.moreResults();
}
/**
*
* @throws BasicException
*/
@Override
public void closeExec() throws BasicException {
sent2.closeExec();
}
}
@@ -0,0 +1,71 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SequenceForMySQL extends BaseSentence {
private BaseSentence sent1;
private BaseSentence sent2;
/** Creates a new instance of SequenceForMySQL
* @param s
* @param sSeqTable */
public SequenceForMySQL(Session s, String sSeqTable) {
sent1 = new StaticSentence(s, "UPDATE " + sSeqTable + " SET ID = LAST_INSERT_ID(ID + 1)");
sent2 = new StaticSentence(s, "SELECT LAST_INSERT_ID()", null, SerializerReadInteger.INSTANCE);
}
// Funciones de bajo nivel
/**
*
* @param params
* @return
* @throws BasicException
*/
public DataResultSet openExec(Object params) throws BasicException {
sent1.exec();
return sent2.openExec(null);
}
/**
*
* @return
* @throws BasicException
*/
public DataResultSet moreResults() throws BasicException {
return sent2.moreResults();
}
/**
*
* @throws BasicException
*/
public void closeExec() throws BasicException {
sent2.closeExec();
}
}
@@ -0,0 +1,48 @@
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
public class SequenceForSQLite extends BaseSentence {
private BaseSentence sent1;
private BaseSentence sent2;
/** Creates a new instance of SequenceForMySQL
* @param s
* @param sSeqTable */
public SequenceForSQLite(Session s, String sSeqTable) {
sent1 = new StaticSentence(s, "UPDATE " + sSeqTable + " SET ID = last_insert_rowid()+1");
sent2 = new StaticSentence(s, "SELECT last_insert_rowid()", null, SerializerReadInteger.INSTANCE);
}
// Funciones de bajo nivel
/**
*
* @param params
* @return
* @throws BasicException
*/
public DataResultSet openExec(Object params) throws BasicException {
sent1.exec();
return sent2.openExec(null);
}
/**
*
* @return
* @throws BasicException
*/
public DataResultSet moreResults() throws BasicException {
return sent2.moreResults();
}
/**
*
* @throws BasicException
*/
public void closeExec() throws BasicException {
sent2.closeExec();
}
}
@@ -0,0 +1,33 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author JG uniCenta
*/
public interface SerializableBuilder {
/**
*
* @return
*/
public SerializableRead createNew();
}
@@ -0,0 +1,36 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public interface SerializableRead {
/**
*
* @param dr
* @throws BasicException
*/
public void readValues(DataRead dr) throws BasicException;
}
@@ -0,0 +1,36 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public interface SerializableWrite {
/**
*
* @param dp
* @throws BasicException
*/
public void writeValues(DataWrite dp) throws BasicException;
}
@@ -0,0 +1,37 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author adrian
*/
public interface SerializerRead {
/**
*
* @param dr
* @return
* @throws BasicException
*/
public Object readValues(DataRead dr) throws BasicException;
}
@@ -0,0 +1,52 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SerializerReadBasic implements SerializerRead {
private Datas[] m_classes;
/** Creates a new instance of SerializerReadBasic
* @param classes */
public SerializerReadBasic(Datas[] classes) {
m_classes = classes;
}
/**
*
* @param dr
* @return
* @throws BasicException
*/
public Object readValues(DataRead dr) throws BasicException {
Object[] m_values = new Object[m_classes.length];
for (int i = 0; i < m_classes.length; i++) {
m_values[i] = m_classes[i].getValue(dr, i + 1);
}
return m_values;
}
}
@@ -0,0 +1,50 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author adrian
*/
public class SerializerReadBuilder implements SerializerRead {
private SerializableBuilder m_sb;
/** Creates a new instance of SerializerReadBuilder
* @param sb */
public SerializerReadBuilder(SerializableBuilder sb) {
m_sb = sb;
}
/**
*
* @param dr
* @return
* @throws BasicException
*/
public Object readValues(DataRead dr) throws BasicException {
SerializableRead sr = m_sb.createNew();
sr.readValues(dr);
return sr;
}
}
@@ -0,0 +1,48 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author Adrian
*/
public class SerializerReadBytes implements SerializerRead {
/**
*
*/
public static final SerializerRead INSTANCE = new SerializerReadBytes();
/** Creates a new instance of SerializerReadBytes */
private SerializerReadBytes() {
}
/**
*
* @param dr
* @return
* @throws BasicException
*/
public Object readValues(DataRead dr) throws BasicException {
return Datas.BYTES.getValue(dr,1);
}
}
@@ -0,0 +1,55 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SerializerReadClass implements SerializerRead {
private final Class m_clazz;
/** Creates a new instance of DefaultSerializerRead
* @param clazz */
public SerializerReadClass(Class clazz) {
m_clazz = clazz;
}
/**
*
* @param dr
* @return
* @throws BasicException
*/
@Override
public Object readValues(DataRead dr) throws BasicException {
try {
SerializableRead sr = (SerializableRead) m_clazz.newInstance();
sr.readValues(dr);
return sr;
// JG 16 May 12 use multicatch
} catch (java.lang.InstantiationException | IllegalAccessException | ClassCastException eIns) {
return null;
}
}
}
@@ -0,0 +1,50 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author James Bolongan
*/
public class SerializerReadDate implements SerializerRead {
/**
*
*/
public static final SerializerRead INSTANCE = new SerializerReadDate();
/** Creates a new instance of SerializerReadImage */
private SerializerReadDate() {
}
/**
*
* @param dr
* @return
* @throws BasicException
*/
@Override
public Object readValues(DataRead dr) throws BasicException {
return Datas.TIMESTAMP.getValue(dr, 1);
}
}
@@ -0,0 +1,48 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SerializerReadDouble implements SerializerRead {
/**
*
*/
public static final SerializerRead INSTANCE = new SerializerReadDouble();
/** Creates a new instance of SerializerReadInteger */
public SerializerReadDouble() {
}
/**
*
* @param dr
* @return
* @throws BasicException
*/
public Object readValues(DataRead dr) throws BasicException {
return Datas.DOUBLE.getValue(dr,1);
}
}
@@ -0,0 +1,49 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SerializerReadImage implements SerializerRead {
/**
*
*/
public static final SerializerRead INSTANCE = new SerializerReadImage();
/** Creates a new instance of SerializerReadImage */
private SerializerReadImage() {
}
/**
*
* @param dr
* @return
* @throws BasicException
*/
public Object readValues(DataRead dr) throws BasicException {
return Datas.IMAGE.getValue(dr,1);
}
}
@@ -0,0 +1,48 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SerializerReadInteger implements SerializerRead {
/**
*
*/
public static final SerializerRead INSTANCE = new SerializerReadInteger();
/** Creates a new instance of SerializerReadInteger */
private SerializerReadInteger() {
}
/**
*
* @param dr
* @return
* @throws BasicException
*/
public Object readValues(DataRead dr) throws BasicException {
return Datas.INT.getValue(dr,1);
}
}
@@ -0,0 +1,48 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SerializerReadString implements SerializerRead {
/**
*
*/
public static final SerializerRead INSTANCE = new SerializerReadString();
/** Creates a new instance of SerializerReadImage */
private SerializerReadString() {
}
/**
*
* @param dr
* @return
* @throws BasicException
*/
public Object readValues(DataRead dr) throws BasicException {
return Datas.STRING.getValue(dr,1);
}
}
@@ -0,0 +1,52 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SerializerReadUTF8 implements SerializerRead {
/**
*
*/
public static final SerializerRead INSTANCE = new SerializerReadUTF8();
/** Creates a new instance of SerializerReadImage */
private SerializerReadUTF8() {
}
/**
*
* @param dr
* @return
* @throws BasicException
*/
public Object readValues(DataRead dr) throws BasicException {
try {
return new String((byte[]) Datas.BYTES.getValue(dr,1), "UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
return null;
}
}
}
@@ -0,0 +1,38 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
* @param <T>
*/
public interface SerializerWrite<T> {
/**
*
* @param dp
* @param obj
* @throws BasicException
*/
public void writeValues(DataWrite dp, T obj) throws BasicException;
}
@@ -0,0 +1,52 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SerializerWriteBasic implements SerializerWrite<Object[]> {
private Datas[] m_classes;
/** Creates a new instance of SerializerWriteBasic
* @param classes */
public SerializerWriteBasic(Datas... classes) {
m_classes = classes;
}
/**
*
* @param dp
* @param obj
* @throws BasicException
*/
@Override
public void writeValues(DataWrite dp, Object[] obj) throws BasicException {
for (int i = 0; i < m_classes.length; i++) {
m_classes[i].setValue(dp, i + 1, obj[i]);
}
}
}
@@ -0,0 +1,55 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SerializerWriteBasicComposed implements SerializerWrite<Object[]> {
private Datas[][] m_classes;
/** Creates a new instance of SerializerWriteComposed
* @param classes */
public SerializerWriteBasicComposed(Datas[]... classes) {
m_classes = classes;
}
/**
*
* @param dp
* @param obj
* @throws BasicException
*/
public void writeValues(DataWrite dp, Object[] obj) throws BasicException {
int index = 0;
for (int i = 0; i < m_classes.length; i++) {
Object[] val = (Object[]) obj[i];
for (int j = 0; j < m_classes[i].length; j++) {
index++;
m_classes[i][j].setValue(dp, index, val[j]);
}
}
}
}
@@ -0,0 +1,55 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SerializerWriteBasicExt implements SerializerWrite<Object[]> {
private Datas[] m_classes;
private int[] m_index;
/** Creates a new instance of SerializerWriteBasic
* @param classes
* @param index */
public SerializerWriteBasicExt(Datas[] classes, int[] index) {
m_classes = classes;
m_index = index;
}
/**
*
* @param dp
* @param obj
* @throws BasicException
*/
@Override
public void writeValues(DataWrite dp, Object[] obj) throws BasicException {
for (int i = 0; i < m_index.length; i++) {
m_classes[m_index[i]].setValue(dp, i + 1, obj[m_index[i]]);
}
}
}
@@ -0,0 +1,48 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SerializerWriteBuilder implements SerializerWrite<SerializableWrite> {
/**
*
*/
public static final SerializerWrite INSTANCE = new SerializerWriteBuilder();
/** Creates a new instance of SerializerWriteBuilder */
private SerializerWriteBuilder() {
}
/**
*
* @param dp
* @param obj
* @throws BasicException
*/
public void writeValues(DataWrite dp, SerializableWrite obj) throws BasicException {
obj.writeValues(dp);
}
}
@@ -0,0 +1,115 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
*
* @author JG uniCenta
*/
public class SerializerWriteComposed implements SerializerWrite {
private List<SerializerWrite> serwrites = new ArrayList<SerializerWrite>();
/** Creates a new instance of SerializerWriteComposed */
public SerializerWriteComposed() {
}
/**
*
* @param sw
*/
public void add(SerializerWrite sw) {
serwrites.add(sw);
}
/**
*
* @param dp
* @param obj
* @throws BasicException
*/
public void writeValues(DataWrite dp, Object obj) throws BasicException {
Object[] a = (Object[]) obj;
DataWriteComposed dpc = new DataWriteComposed(dp);
int i = 0;
for (SerializerWrite sw : serwrites) {
dpc.next();
sw.writeValues(dpc, a[i++]);
}
}
private static class DataWriteComposed implements DataWrite {
private DataWrite dp;
private int offset = 0;
private int max = 0;
public DataWriteComposed(DataWrite dp) {
this.dp = dp;
}
public void next() {
offset = max;
}
public void setInt(int paramIndex, Integer iValue) throws BasicException {
dp.setInt(offset + paramIndex, iValue);
max = Math.max(max, offset + paramIndex);
}
public void setString(int paramIndex, String sValue) throws BasicException {
dp.setString(offset + paramIndex, sValue);
max = Math.max(max, offset + paramIndex);
}
public void setDouble(int paramIndex, Double dValue) throws BasicException {
dp.setDouble(offset + paramIndex, dValue);
max = Math.max(max, offset + paramIndex);
}
public void setBoolean(int paramIndex, Boolean bValue) throws BasicException {
dp.setBoolean(offset + paramIndex, bValue);
max = Math.max(max, offset + paramIndex);
}
public void setTimestamp(int paramIndex, Date dValue) throws BasicException {
dp.setTimestamp(offset + paramIndex, dValue);
max = Math.max(max, offset + paramIndex);
}
public void setBytes(int paramIndex, byte[] value) throws BasicException {
dp.setBytes(offset + paramIndex, value);
max = Math.max(max, offset + paramIndex);
}
public void setObject(int paramIndex, Object value) throws BasicException {
dp.setObject(offset + paramIndex, value);
max = Math.max(max, offset + paramIndex);
}
}
}
@@ -0,0 +1,48 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class SerializerWriteInteger implements SerializerWrite<Integer> {
/**
*
*/
public static final SerializerWrite INSTANCE = new SerializerWriteInteger();
/** Creates a new instance of SerializerWriteInteger */
private SerializerWriteInteger() {
}
/**
*
* @param dp
* @param obj
* @throws BasicException
*/
public void writeValues(DataWrite dp, Integer obj) throws BasicException {
Datas.INT.setValue(dp, 1, obj);
}
}
@@ -0,0 +1,47 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author adrianromero
*/
public class SerializerWriteParams implements SerializerWrite<DataParams>{
/**
*
*/
public static final SerializerWrite INSTANCE = new SerializerWriteParams();
/**
*
* @param dp
* @param obj
* @throws BasicException
*/
@Override
public void writeValues(DataWrite dp, DataParams obj) throws BasicException {
obj.setDataWrite(dp);
obj.writeValues();
obj.setDataWrite(null);
}
}
@@ -0,0 +1,58 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
import java.lang.reflect.Array;
/**
*
* @author JG uniCenta
*/
public class SerializerWriteString implements SerializerWrite<Object> {
/**
*
*/
public static final SerializerWrite INSTANCE = new SerializerWriteString();
/** Creates a new instance of SerializerWriteString */
private SerializerWriteString() {
}
/**
*
* @param dp
* @param obj
* @throws BasicException
*/
public void writeValues(DataWrite dp, Object obj) throws BasicException {
if (obj instanceof Object[]){
for (int i = 0 ; i < ((Object[]) obj).length ; i++) {
Datas.STRING.setValue(dp, i+1, ((Object[]) obj)[i]);
}
}
else {
Datas.STRING.setValue(dp, 1, obj);
}
}
}
@@ -0,0 +1,213 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright © 2009-2020 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author adrianromero
* Created on February 6, 2007, 4:06 PM
*
*/
public final class Session {
private final String m_surl;
private final String m_sappuser;
private final String m_spassword;
private Connection m_c;
private boolean m_bInTransaction;
/**
*
*/
public final SessionDB DB;
/** Creates a new instance of Session
* @param url
* @param user
* @param password
* @throws java.sql.SQLException */
public Session(String url, String user, String password) throws SQLException {
m_surl = url;
m_sappuser = user;
m_spassword = password;
m_c = null;
m_bInTransaction = false;
connect(); // no lazy connection
DB = getDiff();
}
/**
*
* @throws SQLException
*/
public void connect() throws SQLException {
// primero cerramos si no estabamos cerrados
close();
// creamos una nueva conexion.
m_c = (m_sappuser == null && m_spassword == null)
? DriverManager.getConnection(m_surl)
: DriverManager.getConnection(m_surl, m_sappuser, m_spassword);
m_c.setAutoCommit(true);
m_bInTransaction = false;
}
/**
*
*/
public void close() {
if (m_c != null) {
try {
if (m_bInTransaction) {
m_bInTransaction = false; // lo primero salimos del estado
m_c.rollback();
m_c.setAutoCommit(true);
}
m_c.close();
} catch (SQLException e) {
// me la como
} finally {
m_c = null;
}
}
}
/**
*
* @return
* @throws SQLException
*/
public Connection getConnection() throws SQLException {
if (!m_bInTransaction) {
ensureConnection();
}
return m_c;
}
/**
*
* @throws SQLException
*/
public void begin() throws SQLException {
if (m_bInTransaction) {
throw new SQLException("Already in transaction");
} else {
ensureConnection();
m_c.setAutoCommit(false);
m_bInTransaction = true;
}
}
/**
*
* @throws SQLException
*/
public void commit() throws SQLException {
if (m_bInTransaction) {
m_bInTransaction = false; // lo primero salimos del estado
m_c.commit();
m_c.setAutoCommit(true);
} else {
throw new SQLException("Transaction not started");
}
}
/**
*
* @throws SQLException
*/
public void rollback() throws SQLException {
if (m_bInTransaction) {
m_bInTransaction = false; // lo primero salimos del estado
m_c.rollback();
m_c.setAutoCommit(true);
} else {
throw new SQLException("Transaction not started");
}
}
/**
*
* @return
*/
public boolean isTransaction() {
return m_bInTransaction;
}
private void ensureConnection() throws SQLException {
// solo se invoca si isTransaction == false
boolean bclosed;
try {
bclosed = m_c == null || m_c.isClosed();
} catch (SQLException e) {
bclosed = true;
}
// reconnect if closed
if (bclosed) {
connect();
}
}
/**
*
* @return
* @throws SQLException
*/
public String getURL() throws SQLException {
return getConnection().getMetaData().getURL();
}
private SessionDB getDiff() throws SQLException {
String sdbmanager = getConnection().getMetaData().getDatabaseProductName();
switch (sdbmanager) {
case "SQLite":
return new SessionDBSQLite();
case "MariaDB":
return new SessionDBMariaDB();
case "HSQL Database Engine":
return new SessionDBHSQLDB();
case "MySQL":
return new SessionDBMySQL();
case "PostgreSQL":
return new SessionDBPostgreSQL();
case "Oracle":
return new SessionDBOracle();
case "Apache Derby":
return new SessionDBDerby();
default:
return new SessionDBGeneric(sdbmanager);
}
}
}
@@ -0,0 +1,76 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author adrianromero
*/
public interface SessionDB {
/**
*
* @return
*/
public String TRUE();
/**
*
* @return
*/
public String FALSE();
/**
*
* @return
*/
public String INTEGER_NULL();
/**
*
* @return
*/
public String CHAR_NULL();
/**
*
* @return
*/
public String getName();
/**
*
* @param s
* @param sequence
* @return
*/
public SentenceFind getSequenceSentence(Session s, String sequence);
/**
*
* @param s
* @param sequence
* @return
*/
public SentenceFind resetSequenceSentence(Session s, String sequence);
}
@@ -0,0 +1,94 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author adrianromero
*/
public class SessionDBDerby implements SessionDB {
/**
*
* @return
*/
@Override
public String TRUE() {
return "1";
}
/**
*
* @return
*/
@Override
public String FALSE() {
return "0";
}
/**
*
* @return
*/
@Override
public String INTEGER_NULL() {
return "CAST(NULL AS INTEGER)";
}
/**
*
* @return
*/
@Override
public String CHAR_NULL() {
return "CAST(NULL AS CHAR)";
}
/**
*
* @return
*/
@Override
public String getName() {
return "Derby";
}
/**
*
* @param s
* @param sequence
* @return
*/
@Override
public SentenceFind getSequenceSentence(Session s, String sequence) {
return new SequenceForDerby(s, sequence);
}
/**
*
* @param s
* @param sequence
* @return
*/
@Override
public SentenceFind resetSequenceSentence(Session s, String sequence) {
return new SequenceForDerby(s, sequence);
}
}
@@ -0,0 +1,97 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author adrianromero
*/
public class SessionDBGeneric implements SessionDB {
private String name;
/**
*
* @param name
*/
public SessionDBGeneric(String name) {
this.name = name;
}
/**
*
* @return
*/
public String TRUE() {
return "TRUE";
}
/**
*
* @return
*/
public String FALSE() {
return "FALSE";
}
/**
*
* @return
*/
public String INTEGER_NULL() {
return "CAST(NULL AS INTEGER)";
}
/**
*
* @return
*/
public String CHAR_NULL() {
return "CAST(NULL AS CHAR)";
}
/**
*
* @return
*/
public String getName() {
return name;
}
/**
*
* @param s
* @param sequence
* @return
*/
public SentenceFind getSequenceSentence(Session s, String sequence) {
return new StaticSentence(s, "SELECT NEXTVAL('" + sequence + "')", null, SerializerReadInteger.INSTANCE);
}
/**
*
* @param s
* @param sequence
* @return
*/
public SentenceFind resetSequenceSentence(Session s, String sequence){
return new StaticSentence(s, "ALTER SEQUENCE " + sequence + " RESTART WITH 0", null, SerializerReadInteger.INSTANCE);
}
}
@@ -0,0 +1,94 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author adrianromero
*/
public class SessionDBHSQLDB implements SessionDB {
/**
*
* @return
*/
@Override
public String TRUE() {
return "TRUE";
}
/**
*
* @return
*/
@Override
public String FALSE() {
return "FALSE";
}
/**
*
* @return
*/
@Override
public String INTEGER_NULL() {
return "CAST(NULL AS INTEGER)";
}
/**
*
* @return
*/
@Override
public String CHAR_NULL() {
return "CAST(NULL AS CHAR)";
}
/**
*
* @return
*/
@Override
public String getName() {
return "HSQLDB";
}
/**
*
* @param s
* @param sequence
* @return
*/
@Override
public SentenceFind getSequenceSentence(Session s, String sequence) {
return new StaticSentence(s, "CALL NEXT VALUE FOR " + sequence, null, SerializerReadInteger.INSTANCE);
}
/**
*
* @param s
* @param sequence
* @return
*/
@Override
public SentenceFind resetSequenceSentence(Session s, String sequence) {
return new StaticSentence(s, "CALL NEXT VALUE FOR " + sequence, null, SerializerReadInteger.INSTANCE);
}
}
@@ -0,0 +1,89 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author adrianromero
*/
public class SessionDBMariaDB implements SessionDB {
/**
*
* @return
*/
public String TRUE() {
return "TRUE";
}
/**
*
* @return
*/
public String FALSE() {
return "FALSE";
}
/**
*
* @return
*/
public String INTEGER_NULL() {
return "CAST(NULL AS UNSIGNED INTEGER)";
}
/**
*
* @return
*/
public String CHAR_NULL() {
return "CAST(NULL AS CHAR)";
}
/**
*
* @return
*/
public String getName() {
return "MariaDB";
}
/**
*
* @param s
* @param sequence
* @return
*/
@Override
public SentenceFind getSequenceSentence(Session s, String sequence) {
return new SequenceForMySQL(s, sequence);
}
/**
*
* @param s
* @param sequence
* @return
*/
@Override
public SentenceFind resetSequenceSentence(Session s, String sequence) {
return new SequenceForMySQL(s, "UPDATE pickup_number SET ID=1");
}
}
@@ -0,0 +1,89 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author adrianromero
*/
public class SessionDBMySQL implements SessionDB {
/**
*
* @return
*/
public String TRUE() {
return "TRUE";
}
/**
*
* @return
*/
public String FALSE() {
return "FALSE";
}
/**
*
* @return
*/
public String INTEGER_NULL() {
return "CAST(NULL AS UNSIGNED INTEGER)";
}
/**
*
* @return
*/
public String CHAR_NULL() {
return "CAST(NULL AS CHAR)";
}
/**
*
* @return
*/
public String getName() {
return "MySQL";
}
/**
*
* @param s
* @param sequence
* @return
*/
@Override
public SentenceFind getSequenceSentence(Session s, String sequence) {
return new SequenceForMySQL(s, sequence);
}
/**
*
* @param s
* @param sequence
* @return
*/
@Override
public SentenceFind resetSequenceSentence(Session s, String sequence) {
return new SequenceForMySQL(s, "UPDATE pickup_number SET ID=1");
}
}
@@ -0,0 +1,87 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author adrianromero
*/
public class SessionDBOracle implements SessionDB {
/**
*
* @return
*/
public String TRUE() {
return "1";
}
/**
*
* @return
*/
public String FALSE() {
return "0";
}
/**
*
* @return
*/
public String INTEGER_NULL() {
return "CAST(NULL AS INTEGER)";
}
/**
*
* @return
*/
public String CHAR_NULL() {
return "CAST(NULL AS CHAR)";
}
/**
*
* @return
*/
public String getName() {
return "Oracle";
}
/**
*
* @param s
* @param sequence
* @return
*/
public SentenceFind getSequenceSentence(Session s, String sequence) {
return new StaticSentence(s, "SELECT " + sequence + ".NEXTVAL FROM DUAL", null, SerializerReadInteger.INSTANCE);
}
/**
*
* @param s
* @param sequence
* @return
*/
public SentenceFind resetSequenceSentence(Session s, String sequence) {
return new StaticSentence(s, "SELECT " + sequence + ".NEXTVAL FROM DUAL", null, SerializerReadInteger.INSTANCE);
}
}
@@ -0,0 +1,94 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
/**
*
* @author adrianromero
*/
public class SessionDBPostgreSQL implements SessionDB {
/**
*
* @return
*/
@Override
public String TRUE() {
return "True";
}
/**
*
* @return
*/
@Override
public String FALSE() {
return "False";
}
/**
*
* @return
*/
@Override
public String INTEGER_NULL() {
return "CAST(NULL AS INTEGER)";
}
/**
*
* @return
*/
@Override
public String CHAR_NULL() {
return "CAST(NULL AS CHAR)";
}
/**
*
* @return
*/
@Override
public String getName() {
return "PostgreSQL";
}
/**
*
* @param s
* @param sequence
* @return
*/
@Override
public SentenceFind getSequenceSentence(Session s, String sequence) {
return new StaticSentence(s, "SELECT NEXTVAL('" + sequence + "')", null, SerializerReadInteger.INSTANCE);
}
/**
*
* @param s
* @param sequence
* @return
*/
@Override
public SentenceFind resetSequenceSentence(Session s, String sequence){
return new StaticSentence(s, "ALTER SEQUENCE " + sequence + " RESTART WITH '0'", null, SerializerReadInteger.INSTANCE);
}
}
@@ -0,0 +1,70 @@
package com.unicenta.data.loader;
/**
*
* @author adrianromero
*/
public class SessionDBSQLite implements SessionDB {
/**
*
* @return
*/
public String TRUE() {
return "1";
}
/**
*
* @return
*/
public String FALSE() {
return "0";
}
/**
*
* @return
*/
public String INTEGER_NULL() {
return "CAST(NULL AS UNSIGNED INTEGER)";
}
/**
*
* @return
*/
public String CHAR_NULL() {
return "CAST(NULL AS CHAR)";
}
/**
*
* @return
*/
public String getName() {
return "SQLite";
}
/**
*
* @param s
* @param sequence
* @return
*/
@Override
public SentenceFind getSequenceSentence(Session s, String sequence) {
return new SequenceForSQLite(s, sequence);
}
/**
*
* @param s
* @param sequence
* @return
*/
@Override
public SentenceFind resetSequenceSentence(Session s, String sequence) {
return new SequenceForSQLite(s, "UPDATE pickup_number SET ID=1");
}
}
@@ -0,0 +1,49 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author adrian
*/
public class SimpleBuilder implements ISQLBuilderStatic {
private String m_sSentence;
/** Creates a new instance of SimpleBuilder
* @param sSentence */
public SimpleBuilder(String sSentence) {
m_sSentence = sSentence;
}
/**
*
* @param sw
* @param params
* @return
* @throws BasicException
*/
public String getSQL(SerializerWrite sw, Object params) throws BasicException {
return m_sSentence;
}
}
@@ -0,0 +1,224 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
import lombok.extern.slf4j.Slf4j;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author adrianromero
*/
@Slf4j
public class StaticSentence extends JDBCSentence {
private ISQLBuilderStatic iSQLBuilder;
/**
*
*/
protected SerializerWrite m_SerWrite = null;
/**
*
*/
protected SerializerRead m_SerRead = null;
// Estado
private Statement statement;
/**
* Creates a new instance of StaticSentence
*
* @param s
* @param sentence
* @param serread
* @param serwrite
*/
public StaticSentence(Session s, ISQLBuilderStatic sentence, SerializerWrite serwrite, SerializerRead serread) {
super(s);
iSQLBuilder = sentence;
m_SerWrite = serwrite;
m_SerRead = serread;
statement = null;
}
/**
* Creates a new instance of StaticSentence
*
* @param s
* @param sentence
*/
public StaticSentence(Session s, ISQLBuilderStatic sentence) {
this(s, sentence, null, null);
}
/**
* Creates a new instance of StaticSentence
*
* @param s
* @param sentence
* @param serwrite
*/
public StaticSentence(Session s, ISQLBuilderStatic sentence, SerializerWrite serwrite) {
this(s, sentence, serwrite, null);
}
/**
* Creates a new instance of StaticSentence
*
* @param s
* @param sentence
* @param serread
* @param serwrite
*/
public StaticSentence(Session s, String sentence, SerializerWrite serwrite, SerializerRead serread) {
this(s, new NormalBuilder(sentence), serwrite, serread);
}
/**
* Creates a new instance of StaticSentence
*
* @param s
* @param sentence
* @param serwrite
*/
public StaticSentence(Session s, String sentence, SerializerWrite serwrite) {
this(s, new NormalBuilder(sentence), serwrite, null);
}
/**
* Creates a new instance of StaticSentence
*
* @param s
* @param sentence
*/
public StaticSentence(Session s, String sentence) {
this(s, new NormalBuilder(sentence), null, null);
}
public String fixSqliteDate(String sql) {
try {
if (session.getURL().contains("sqlite") && sql.contains("{ts '")) {
StringBuilder sqliteSQL = new StringBuilder();
Pattern date = Pattern.compile("(?<=ts ).*(?=})");
Matcher matchPattern = date.matcher(sql);
if (matchPattern.find()) {
sqliteSQL.append(sql.replaceAll("\\{.*}", matchPattern.group(0)));
}
return sqliteSQL.toString();
}
}
catch (Exception e) {
log.error("Error fixing sql for sqlite {}", e.getMessage());
return sql;
}
return sql;
}
/**
* @param params
* @return
* @throws BasicException
*/
@Override
public DataResultSet openExec(Object params) throws BasicException {
// true -> un resultset
// false -> un updatecount (si -1 entonces se acabo)
closeExec();
try {
String sentence = fixSqliteDate(iSQLBuilder.getSQL(m_SerWrite, params));
//String sentence = iSQLBuilder.getSQL(m_SerWrite, params);
statement = session.getConnection().createStatement();
log.debug("Executing static SQL: {}", sentence);
if (statement.execute(sentence)) {
return new JDBCDataResultSet(statement.getResultSet(), m_SerRead);
} else {
int iUC = statement.getUpdateCount();
if (iUC < 0) {
return null;
} else {
return new SentenceUpdateResultSet(iUC);
}
}
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
/**
* @throws BasicException
*/
@Override
public void closeExec() throws BasicException {
if (statement != null) {
try {
statement.close();
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
} finally {
statement = null;
}
}
}
/**
* @return
* @throws BasicException
*/
@Override
public DataResultSet moreResults() throws BasicException {
try {
if (statement.getMoreResults()) {
// tenemos resultset
return new JDBCDataResultSet(statement.getResultSet(), m_SerRead);
} else {
// tenemos updatecount o si devuelve -1 ya no hay mas
int iUC = statement.getUpdateCount();
if (iUC < 0) {
return null;
} else {
return new SentenceUpdateResultSet(iUC);
}
}
} catch (SQLException eSQL) {
throw new BasicException(eSQL);
}
}
}
@@ -0,0 +1,349 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.format.Formats;
/**
*
* @author JG uniCenta
*/
public class TableDefinition {
private Session m_s;
private String tablename;
private String[] fieldname;
private String[] fieldtran;
private Datas[] fielddata;
private Formats[] fieldformat;
private int[] idinx;
/** Creates a new instance of TableDefinition
* @param s
* @param fieldformat
* @param tablename
* @param fieldname
* @param fieldtran
* @param idinx
* @param fielddata */
public TableDefinition(
Session s,
String tablename,
String[] fieldname, String[] fieldtran, Datas[] fielddata, Formats[] fieldformat,
int[] idinx) {
m_s = s;
this.tablename = tablename;
this.fieldname = fieldname;
this.fieldtran = fieldtran;
this.fielddata = fielddata;
this.fieldformat = fieldformat;
this.idinx = idinx;
}
/**
*
* @param s
* @param tablename
* @param fieldname
* @param fielddata
* @param fieldformat
* @param idinx
*/
public TableDefinition(
Session s,
String tablename,
String[] fieldname, Datas[] fielddata, Formats[] fieldformat,
int[] idinx) {
this(s, tablename, fieldname, fieldname, fielddata, fieldformat, idinx);
}
/**
*
* @return
*/
public String getTableName() {
return tablename;
}
/**
*
* @return
*/
public String[] getFields() {
return fieldname;
}
/**
*
* @param aiFields
* @return
*/
public Vectorer getVectorerBasic(int[] aiFields) {
return new VectorerBasic(fieldtran, fieldformat, aiFields);
}
/**
*
* @param aiFields
* @return
*/
public IRenderString getRenderStringBasic(int[] aiFields) {
return new RenderStringBasic(fieldformat, aiFields);
}
/**
*
* @param aiOrders
* @return
*/
public ComparatorCreator getComparatorCreator(int [] aiOrders) {
return new ComparatorCreatorBasic(fieldtran, fielddata, aiOrders);
}
/**
*
* @return
*/
public IKeyGetter getKeyGetterBasic() {
if (idinx.length == 1) {
return new KeyGetterFirst(idinx);
} else {
return new KeyGetterBasic(idinx);
}
}
/**
*
* @return
*/
public SerializerRead getSerializerReadBasic() {
return new SerializerReadBasic(fielddata);
}
/**
*
* @param fieldindx
* @return
*/
public SerializerWrite getSerializerInsertBasic(int[] fieldindx) {
return new SerializerWriteBasicExt(fielddata, fieldindx);
}
/**
*
* @return
*/
public SerializerWrite getSerializerDeleteBasic() {
return new SerializerWriteBasicExt(fielddata, idinx);
}
/**
*
* @param fieldindx
* @return
*/
public SerializerWrite getSerializerUpdateBasic(int[] fieldindx) {
int[] aindex = new int[fieldindx.length + idinx.length];
for (int i = 0; i < fieldindx.length; i++) {
aindex[i] = fieldindx[i];
}
for (int i = 0; i < idinx.length; i++) {
aindex[i + fieldindx.length] = idinx[i];
}
return new SerializerWriteBasicExt(fielddata, aindex);
}
/**
*
* @return
*/
public SentenceList getListSentence() {
return getListSentence(getSerializerReadBasic());
}
/**
*
* @param sr
* @return
*/
public SentenceList getListSentence(SerializerRead sr) {
return new PreparedSentence(m_s, getListSQL(), null, sr);
}
/**
*
* @return
*/
public String getListSQL() {
StringBuilder sent = new StringBuilder();
sent.append("select ");
for (int i = 0; i < fieldname.length; i ++) {
if (i > 0) {
sent.append(", ");
}
sent.append(fieldname[i]);
}
sent.append(" from ");
sent.append(tablename);
return sent.toString();
}
/**
*
* @return
*/
public SentenceExec getDeleteSentence() {
return getDeleteSentence(getSerializerDeleteBasic());
}
/**
*
* @param sw
* @return
*/
public SentenceExec getDeleteSentence(SerializerWrite sw) {
return new PreparedSentence(m_s, getDeleteSQL(), sw, null);
}
/**
*
* @return
*/
public String getDeleteSQL() {
StringBuilder sent = new StringBuilder();
sent.append("delete from ");
sent.append(tablename);
for (int i = 0; i < idinx.length; i ++) {
sent.append((i == 0) ? " where " : " and ");
sent.append(fieldname[idinx[i]]);
sent.append(" = ?");
}
return sent.toString();
}
/**
*
* @return
*/
public SentenceExec getInsertSentence() {
return getInsertSentence(getAllFields());
}
/**
*
* @param fieldindx
* @return
*/
public SentenceExec getInsertSentence(int[] fieldindx) {
return new PreparedSentence(m_s, getInsertSQL(fieldindx), getSerializerInsertBasic(fieldindx), null);
}
private String getInsertSQL(int[] fieldindx) {
StringBuilder sent = new StringBuilder();
StringBuilder values = new StringBuilder();
sent.append("insert into ");
sent.append(tablename);
sent.append(" (");
for (int i = 0; i < fieldindx.length; i ++) {
if (i > 0) {
sent.append(", ");
values.append(", ");
}
sent.append(fieldname[fieldindx[i]]);
values.append("?");
}
sent.append(") values (");
sent.append(values.toString());
sent.append(")");
return sent.toString();
}
private int[] getAllFields() {
int[] fieldindx = new int[fieldname.length];
for (int i = 0; i < fieldname.length; i++) {
fieldindx[i] = i;
}
return fieldindx;
}
/**
*
* @return
*/
public SentenceExec getUpdateSentence() {
return getUpdateSentence(getAllFields());
}
/**
*
* @param fieldindx
* @return
*/
public SentenceExec getUpdateSentence(int[] fieldindx) {
return new PreparedSentence(m_s, getUpdateSQL(fieldindx), getSerializerUpdateBasic(fieldindx), null);
}
private String getUpdateSQL(int[] fieldindx) {
StringBuilder sent = new StringBuilder();
sent.append("update ");
sent.append(tablename);
sent.append(" set ");
for (int i = 0; i < fieldindx.length; i ++) {
if (i > 0) {
sent.append(", ");
}
sent.append(fieldname[fieldindx[i]]);
sent.append(" = ?");
}
for (int i = 0; i < idinx.length; i ++) {
sent.append((i == 0) ? " where " : " and ");
sent.append(fieldname[idinx[i]]);
sent.append(" = ?");
}
return sent.toString();
}
}
@@ -0,0 +1,83 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2013 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
import com.unicenta.pos.forms.AppViewConnection;
import com.unicenta.pos.forms.DataLogicSales;
import com.unicenta.data.loader.Session;
import com.unicenta.pos.forms.AppConfig;
import com.unicenta.pos.forms.AppLocal;
import java.io.*;
public class TicketFooter {
private String footer_line1;
private String footer_line2;
private String footer_line3;
private String footer_line4;
private String footer_line5;
private String footer_line6;
private File m_config;
private Session session;
public TicketFooter() {
AppConfig config = new AppConfig(m_config);
// AppViewConnection Session = new AppViewConnection();
}
public void loadProperties(AppConfig config) {
footer_line1=(config.getProperty("till.footer1"));
footer_line2=(config.getProperty("till.footer2"));
footer_line3=(config.getProperty("till.footer3"));
footer_line4=(config.getProperty("till.footer4"));
footer_line5=(config.getProperty("till.footer5"));
footer_line6=(config.getProperty("till.footer6"));
}
public String getTicketFooterLine1() {
return footer_line1;
}
public String getTicketFooterLine2() {
return footer_line2;
}
public String getTicketFooterLine3() {
return footer_line3;
}
public String getTicketFooterLine4() {
return footer_line4;
}
public String getTicketFooterLine5() {
return footer_line5;
}
public String getTicketFooterLine6() {
return footer_line6;
}
}
@@ -0,0 +1,83 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2013 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
import com.unicenta.pos.forms.AppViewConnection;
import com.unicenta.pos.forms.DataLogicSales;
import com.unicenta.data.loader.Session;
import com.unicenta.pos.forms.AppConfig;
import com.unicenta.pos.forms.AppLocal;
import java.io.*;
public class TicketHeader {
private String header_line1;
private String header_line2;
private String header_line3;
private String header_line4;
private String header_line5;
private String header_line6;
private File m_config;
private Session session;
public TicketHeader() {
AppConfig config = new AppConfig(m_config);
// AppViewConnection Session = new AppViewConnection();
}
public void loadProperties(AppConfig config) {
header_line1=(config.getProperty("till.header1"));
header_line2=(config.getProperty("till.header2"));
header_line3=(config.getProperty("till.header3"));
header_line4=(config.getProperty("till.header4"));
header_line5=(config.getProperty("till.header5"));
header_line6=(config.getProperty("till.header6"));
}
public String getTicketHeaderLine1() {
return header_line1;
}
public String getTicketHeaderLine2() {
return header_line2;
}
public String getTicketHeaderLine3() {
return header_line3;
}
public String getTicketHeaderLine4() {
return header_line4;
}
public String getTicketHeaderLine5() {
return header_line5;
}
public String getTicketHeaderLine6() {
return header_line6;
}
}
@@ -0,0 +1,74 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
import java.sql.SQLException;
/**
*
* @author adrianromero
* Created on 26 de febrero de 2007, 21:50
* @param <T>
*
*/
public abstract class Transaction<T> {
private Session s;
/** Creates a new instance of Transaction
* @param s */
public Transaction(Session s) {
this.s = s;
}
/**
*
* @return
* @throws BasicException
*/
public final T execute() throws BasicException {
if (s.isTransaction()) {
return transact();
} else {
try {
try {
s.begin();
T result = transact();
s.commit();
return result;
} catch (BasicException e) {
s.rollback();
throw e;
}
} catch (SQLException eSQL) {
throw new BasicException("Transaction error", eSQL);
}
}
}
/**
*
* @return
* @throws BasicException
*/
protected abstract T transact() throws BasicException;
}
@@ -0,0 +1,46 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public interface Vectorer {
// public int size();
/**
*
* @return
* @throws BasicException
*/
public String[] getHeaders() throws BasicException;
/**
*
* @param obj
* @return
* @throws BasicException
*/
public String[] getValues(Object obj) throws BasicException;
}
@@ -0,0 +1,77 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import com.unicenta.format.Formats;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public class VectorerBasic implements Vectorer {
private int[] m_aiIndex;
private String[] m_asHeaders;
private Formats[] m_aFormats;
/**
*
* @param asHeaders
* @param aFormats
* @param aiIndex
*/
public VectorerBasic(String[] asHeaders, Formats[] aFormats, int[] aiIndex) {
m_asHeaders = asHeaders;
m_aFormats = aFormats;
m_aiIndex = aiIndex;
}
/**
*
* @return
* @throws BasicException
*/
public String[] getHeaders() throws BasicException {
String[] asvalues = new String[m_aiIndex.length];
for (int i = 0; i < m_aiIndex.length; i++) {
asvalues[i] = m_asHeaders[m_aiIndex[i]];
}
return asvalues;
}
/**
*
* @param obj
* @return
* @throws BasicException
*/
public String[] getValues(Object obj) throws BasicException {
Object[] avalues = (Object[]) obj;
String[] asvalues = new String[m_aiIndex.length];
for (int i = 0; i < m_aiIndex.length; i++) {
asvalues[i] = m_aFormats[m_aiIndex[i]].formatValue(avalues[m_aiIndex[i]]);
}
return asvalues;
}
}
@@ -0,0 +1,108 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.data.loader;
import java.util.*;
import com.unicenta.basic.BasicException;
/**
*
* @author JG uniCenta
*/
public abstract class VectorerBuilder implements Vectorer {
/** Creates a new instance of VectorerBuilder */
public VectorerBuilder() {
}
/**
*
* @return
* @throws BasicException
*/
public abstract String[] getHeaders() throws BasicException;
/**
*
* @param obj
* @return
* @throws BasicException
*/
public String[] getValues(Object obj) throws BasicException {
SerializableToArray s2a = new SerializableToArray();
((SerializableWrite) obj).writeValues(s2a);
return s2a.getValues();
}
private static class SerializableToArray implements DataWrite {
private ArrayList m_aParams;
/** Creates a new instance of MetaParameter */
public SerializableToArray() {
m_aParams = new ArrayList();
}
public void setDouble(int paramIndex, Double dValue) throws BasicException {
ensurePlace(paramIndex - 1);
m_aParams.set(paramIndex - 1, dValue.toString());
}
public void setBoolean(int paramIndex, Boolean bValue) throws BasicException {
ensurePlace(paramIndex - 1);
m_aParams.set(paramIndex - 1, bValue.toString());
}
public void setInt(int paramIndex, Integer iValue) throws BasicException {
ensurePlace(paramIndex - 1);
m_aParams.set(paramIndex - 1, iValue.toString());
}
public void setString(int paramIndex, String sValue) throws BasicException {
ensurePlace(paramIndex - 1);
m_aParams.set(paramIndex - 1, sValue);
}
public void setTimestamp(int paramIndex, java.util.Date dValue) throws BasicException {
ensurePlace(paramIndex - 1);
m_aParams.set(paramIndex - 1, dValue.toString());
}
// public void setBinaryStream(int paramIndex, java.io.InputStream in, int length) throws DataException {
// ensurePlace(paramIndex -1);
// // m_aParams.set(paramIndex - 1, value.toString()); // quiza un uuencode o algo asi
// }
public void setBytes(int paramIndex, byte[] value) throws BasicException {
ensurePlace(paramIndex -1);
m_aParams.set(paramIndex - 1, value.toString()); // quiza un uuencode o algo asi
}
public void setObject(int paramIndex, Object value) throws BasicException {
ensurePlace(paramIndex - 1);
m_aParams.set(paramIndex - 1, value.toString());
}
private void ensurePlace(int i) {
m_aParams.ensureCapacity(i);
while (i >= m_aParams.size()){
m_aParams.add(null);
}
}
public String[] getValues() {
return (String[]) m_aParams.toArray(new String[m_aParams.size()]);
}
}
}