Skip to content
Snippets Groups Projects
Commit 6c8680d1 authored by brinn's avatar brinn
Browse files

Create count query when creating code generator.

SVN: 27582
parent 14280b3d
No related branches found
No related tags found
No related merge requests found
...@@ -38,14 +38,33 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.TableNames; ...@@ -38,14 +38,33 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.TableNames;
*/ */
public class EntityCodeGenerator public class EntityCodeGenerator
{ {
private final IDAOFactory daoFactory;
private IDAOFactory daoFactory; private final CountQuery countQuery;
private Query query; private interface CountQuery extends BaseQuery
{
public final static String PREFIX = "SELECT count(*) FROM ";
public final static String SUFFIX = " WHERE code = ?{1}";
@Select(sql = PREFIX + TableNames.EXPERIMENTS_ALL_TABLE + SUFFIX)
public int getExperimentCount(String code);
@Select(sql = PREFIX + TableNames.SAMPLES_ALL_TABLE + SUFFIX)
public int getSampleCount(String code);
@Select(sql = PREFIX + TableNames.DATA_ALL_TABLE + SUFFIX)
public int getDataSetCount(String code);
@Select(sql = PREFIX + TableNames.MATERIALS_TABLE + SUFFIX)
public int getMaterialsCount(String code);
}
public EntityCodeGenerator(IDAOFactory daoFactory) public EntityCodeGenerator(IDAOFactory daoFactory)
{ {
this.daoFactory = daoFactory; this.daoFactory = daoFactory;
this.countQuery = QueryTool.getManagedQuery(CountQuery.class);
} }
public String generateCode(String codePrefix, EntityKind entityKind) public String generateCode(String codePrefix, EntityKind entityKind)
...@@ -64,10 +83,7 @@ public class EntityCodeGenerator ...@@ -64,10 +83,7 @@ public class EntityCodeGenerator
*/ */
public List<String> generateCodes(String codePrefix, EntityKind entityKind, int numberOfCodes) public List<String> generateCodes(String codePrefix, EntityKind entityKind, int numberOfCodes)
{ {
String[] codes = new String[numberOfCodes]; final String[] codes = new String[numberOfCodes];
query = QueryTool.getManagedQuery(Query.class);
for (int i = 0; i < numberOfCodes; i++) for (int i = 0; i < numberOfCodes; i++)
{ {
long sequenceValue; long sequenceValue;
...@@ -92,16 +108,16 @@ public class EntityCodeGenerator ...@@ -92,16 +108,16 @@ public class EntityCodeGenerator
if (EntityKind.EXPERIMENT.equals(entityKind)) if (EntityKind.EXPERIMENT.equals(entityKind))
{ {
count = query.getExperimentCount(code); count = countQuery.getExperimentCount(code);
} else if (EntityKind.SAMPLE.equals(entityKind)) } else if (EntityKind.SAMPLE.equals(entityKind))
{ {
count = query.getSampleCount(code); count = countQuery.getSampleCount(code);
} else if (EntityKind.DATA_SET.equals(entityKind)) } else if (EntityKind.DATA_SET.equals(entityKind))
{ {
count = query.getDataSetCount(code); count = countQuery.getDataSetCount(code);
} else if (EntityKind.MATERIAL.equals(entityKind)) } else if (EntityKind.MATERIAL.equals(entityKind))
{ {
count = query.getMaterialsCount(code); count = countQuery.getMaterialsCount(code);
} else } else
{ {
throw new IllegalArgumentException("Unsupported entity kind: " + entityKind); throw new IllegalArgumentException("Unsupported entity kind: " + entityKind);
...@@ -110,25 +126,4 @@ public class EntityCodeGenerator ...@@ -110,25 +126,4 @@ public class EntityCodeGenerator
return count > 0; return count > 0;
} }
private interface Query extends BaseQuery
{
public final static String PREFIX = "SELECT count(*) FROM ";
public final static String SUFFIX = " WHERE code = ?{1}";
@Select(sql = PREFIX + TableNames.EXPERIMENTS_ALL_TABLE + SUFFIX)
public int getExperimentCount(String code);
@Select(sql = PREFIX + TableNames.SAMPLES_ALL_TABLE + SUFFIX)
public int getSampleCount(String code);
@Select(sql = PREFIX + TableNames.DATA_ALL_TABLE + SUFFIX)
public int getDataSetCount(String code);
@Select(sql = PREFIX + TableNames.MATERIALS_TABLE + SUFFIX)
public int getMaterialsCount(String code);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment