|
|
|
@ -2,14 +2,15 @@ |
|
|
|
package de.srsoftware.umbrella.company; |
|
|
|
package de.srsoftware.umbrella.company; |
|
|
|
|
|
|
|
|
|
|
|
import static de.srsoftware.tools.jdbc.Condition.equal; |
|
|
|
import static de.srsoftware.tools.jdbc.Condition.equal; |
|
|
|
|
|
|
|
import static de.srsoftware.tools.jdbc.Condition.like; |
|
|
|
import static de.srsoftware.tools.jdbc.Query.*; |
|
|
|
import static de.srsoftware.tools.jdbc.Query.*; |
|
|
|
import static de.srsoftware.tools.jdbc.Query.Dialect.SQLITE; |
|
|
|
import static de.srsoftware.tools.jdbc.Query.Dialect.SQLITE; |
|
|
|
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL; |
|
|
|
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL; |
|
|
|
import static de.srsoftware.umbrella.company.Constants.TABLE_COMPANIES; |
|
|
|
import static de.srsoftware.umbrella.company.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.company.Constants.TABLE_COMPANIES_USERS; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.core.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException; |
|
|
|
import static java.lang.System.Logger.Level.ERROR; |
|
|
|
import static java.lang.System.Logger.Level.ERROR; |
|
|
|
|
|
|
|
import static java.text.MessageFormat.format; |
|
|
|
|
|
|
|
|
|
|
|
import de.srsoftware.umbrella.company.api.CompanyDb; |
|
|
|
import de.srsoftware.umbrella.company.api.CompanyDb; |
|
|
|
import de.srsoftware.umbrella.core.BaseDb; |
|
|
|
import de.srsoftware.umbrella.core.BaseDb; |
|
|
|
@ -17,10 +18,8 @@ import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
|
|
import de.srsoftware.umbrella.core.model.Company; |
|
|
|
import de.srsoftware.umbrella.core.model.Company; |
|
|
|
import java.sql.Connection; |
|
|
|
import java.sql.Connection; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.*; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import org.json.JSONObject; |
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
|
|
|
|
public class SqliteDb extends BaseDb implements CompanyDb { |
|
|
|
public class SqliteDb extends BaseDb implements CompanyDb { |
|
|
|
@ -126,6 +125,26 @@ CREATE TABLE IF NOT EXISTS "companies" ( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public HashMap<Long, Company> find(long userId, Collection<String> keys) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
var query = select(DISTINCT).from(TABLE_COMPANIES).leftJoin(ID,TABLE_COMPANIES_USERS,COMPANY_ID) |
|
|
|
|
|
|
|
.where(USER_ID,equal(userId)); |
|
|
|
|
|
|
|
for (var key : keys){ |
|
|
|
|
|
|
|
query.where(format("CONCAT({0},\" \",{1},\" \",{2},\" \",{3},\" \",{4})",NAME,ADDRESS,EMAIL,FIELD_PHONE,FIELD_BANK_ACCOUNT),like("%"+key+"%")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var rs = query.exec(db); |
|
|
|
|
|
|
|
var companies = new HashMap<Long,Company>(); |
|
|
|
|
|
|
|
while (rs.next()) { |
|
|
|
|
|
|
|
var company = Company.of(rs); |
|
|
|
|
|
|
|
companies.put(company.id(),company); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
rs.close(); |
|
|
|
|
|
|
|
return companies; |
|
|
|
|
|
|
|
} catch (SQLException ex){ |
|
|
|
|
|
|
|
throw databaseException("Failed to search in company database!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Map<Long,Company> listCompaniesOf(long userId) throws UmbrellaException { |
|
|
|
public Map<Long,Company> listCompaniesOf(long userId) throws UmbrellaException { |
|
|
|
|