Skip to content

Commit

Permalink
added final when needed and other minors
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco-Sulla committed May 10, 2019
1 parent 367b821 commit 69528a8
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 104 deletions.
4 changes: 2 additions & 2 deletions src/codefile/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import {pack_model}.{class_name};
public class {class_name}Aggregator {{
{indent}private {class_name} {varname};
{indent}
{indent}public {class_name} get{class_name}() {{
{indent}{indent}return this.{varname};
{indent}}}
{indent}
{indent}public void set{class_name}({class_name} {varname}) {{
{indent}public void set{class_name}(final {class_name} {varname}) {{
{indent}{indent}this.{varname} = {varname};
{indent}}}
}}
Expand All @@ -33,4 +34,3 @@ def write(config):
)

util.writeToFile(config.data_dir, config.pack_aggregator, config.class_name + "Aggregator.java", aggregator)

5 changes: 2 additions & 3 deletions src/codefile/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class {class_name} {{"""
)

model_end = "}\n\n"
model_end = "}\n"

field_col_tpl = "{indent}private {type} {name};"

Expand All @@ -23,7 +23,7 @@
)

setter_col_tpl = (
"""{indent}public void set{methname}({type} {name}) {{
"""{indent}public void set{methname}(final {type} {name}) {{
{indent}{indent}this.{name} = {name};
{indent}}}
{indent}
Expand Down Expand Up @@ -80,4 +80,3 @@ def write(config):
)

util.writeToFile(config.data_dir, config.pack_model, config.class_name + ".java", model)

97 changes: 49 additions & 48 deletions src/codefile/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@
import {pack_model}.{class_name};
import {pack_utility}.Sql2oUtility;
@Repository
public class {class_name}RepositoryImpl implements {class_name}Repository {{
{indent}private final static Logger logger = LoggerFactory.getLogger({class_name}Repository.class);
{indent}
{indent}@Autowired
{indent}private Sql2o sql2o;
{indent}
{indent}private static String getSelectBase(List<String> fields_to_ignore) {{
{indent}private static String getSelectBase(final List<String> fields_to_ignore) {{
{select_fields}
{indent}{indent}return res;
{indent}}}
{indent}
{indent}@Override
{indent}public {class_name} {select_methods_prefix}By{methid}({idsfirm}, List<String> fields_to_ignore, Connection con) {{
{indent}public {class_name} {select_methods_prefix}By{methid}({idsfirm}, final List<String> fields_to_ignore, final Connection con) {{
{indent}{indent}logger.debug("DB>> {select_methods_prefix}By{methid}() - {idslog});
{indent}{indent}
{indent}{indent}String sql = "select " + {class_name}RepositoryImpl.getSelectBase(fields_to_ignore) + "from {table_name} {initial} ";
Expand All @@ -51,13 +52,13 @@
{indent}}}
{indent}
{indent}@Override
{indent}public {class_name} {select_methods_prefix}By{methid}({idsfirm}, Connection con) {{
{indent}{indent}return {select_methods_prefix}By{methid}({idslist}, null, con);
{indent}public {class_name} {select_methods_prefix}By{methid}({idsfirm}, final Connection con) {{
{indent}{indent}return this.{select_methods_prefix}By{methid}({idslist}, null, con);
{indent}}}
{indent}
{indent}@Override
{indent}public {class_name} {select_methods_prefix}By{methid}({idsfirm}, List<String> fields_to_ignore) {{
{indent}{indent}try (Connection con = sql2o.open()) {{
{indent}public {class_name} {select_methods_prefix}By{methid}({idsfirm}, final List<String> fields_to_ignore) {{
{indent}{indent}try (Connection con = this.sql2o.open()) {{
{indent}{indent}{indent}return this.{select_methods_prefix}By{methid}({idslist}, fields_to_ignore, con);
{indent}{indent}}}
{indent}}}
Expand All @@ -68,10 +69,10 @@
{indent}}}
{indent}
{indent}@Override
{indent}public List<{class_name}> {select_methods_prefix}All(List<String> fields_to_ignore, Connection con) {{
{indent}public List<{class_name}> {select_methods_prefix}All(final List<String> fields_to_ignore, final Connection con) {{
{indent}{indent}logger.debug("DB>> {select_methods_prefix}All()");
{indent}{indent}
{indent}{indent}String sql = "select " + {class_name}RepositoryImpl.getSelectBase(fields_to_ignore) + "from {table_name} {initial} ";
{indent}{indent}final String sql = "select " + {class_name}RepositoryImpl.getSelectBase(fields_to_ignore) + "from {table_name} {initial} ";
{indent}{indent}
{indent}{indent}List<{class_name}> res;
{indent}{indent}
Expand All @@ -84,24 +85,24 @@
{indent}}}
{indent}
{indent}@Override
{indent}public List<{class_name}> {select_methods_prefix}All(Connection con) {{
{indent}{indent}return {select_methods_prefix}All(null, con);
{indent}public List<{class_name}> {select_methods_prefix}All(final Connection con) {{
{indent}{indent}return this.{select_methods_prefix}All(null, con);
{indent}}}
{indent}
{indent}@Override
{indent}public List<{class_name}> {select_methods_prefix}All(List<String> fields_to_ignore) {{
{indent}{indent}try (Connection con = sql2o.open()) {{
{indent}public List<{class_name}> {select_methods_prefix}All(final List<String> fields_to_ignore) {{
{indent}{indent}try (Connection con = this.sql2o.open()) {{
{indent}{indent}{indent}return this.{select_methods_prefix}All(fields_to_ignore, con);
{indent}{indent}}}
{indent}}}
{indent}
{indent}@Override
{indent}public List<{class_name}> {select_methods_prefix}All() {{
{indent}{indent}return {select_methods_prefix}All((List<String>) null);
{indent}{indent}return this.{select_methods_prefix}All((List<String>) null);
{indent}}}
{indent}
{indent}@Override
{indent}public List<{class_name}> {select_methods_prefix}ByModel({class_name} {varname}, List<String> fields_to_ignore, Connection con) {{
{indent}public List<{class_name}> {select_methods_prefix}ByModel(final {class_name} {varname}, final List<String> fields_to_ignore, final Connection con) {{
{indent}{indent}logger.debug("DB>> {select_methods_prefix}ByModel()");
{indent}{indent}
{indent}{indent}String sql = "select " + {class_name}RepositoryImpl.getSelectBase(fields_to_ignore) + "from {table_name} {initial} ";
Expand All @@ -122,27 +123,27 @@
{indent}}}
{indent}
{indent}@Override
{indent}public List<{class_name}> {select_methods_prefix}ByModel({class_name} {varname}, Connection con) {{
{indent}{indent}return {select_methods_prefix}ByModel({varname}, null, con);
{indent}public List<{class_name}> {select_methods_prefix}ByModel(final {class_name} {varname}, final Connection con) {{
{indent}{indent}return this.{select_methods_prefix}ByModel({varname}, null, con);
{indent}}}
{indent}
{indent}@Override
{indent}public List<{class_name}> {select_methods_prefix}ByModel({class_name} {varname}, List<String> fields_to_ignore) {{
{indent}{indent}try (Connection con = sql2o.open()) {{
{indent}public List<{class_name}> {select_methods_prefix}ByModel(final {class_name} {varname}, final List<String> fields_to_ignore) {{
{indent}{indent}try (Connection con = this.sql2o.open()) {{
{indent}{indent}{indent}return this.{select_methods_prefix}ByModel({varname}, fields_to_ignore, con);
{indent}{indent}}}
{indent}}}
{indent}
{indent}@Override
{indent}public List<{class_name}> {select_methods_prefix}ByModel({class_name} {varname}) {{
{indent}{indent}return {select_methods_prefix}ByModel({varname}, (List<String>) null);
{indent}public List<{class_name}> {select_methods_prefix}ByModel(final {class_name} {varname}) {{
{indent}{indent}return this.{select_methods_prefix}ByModel({varname}, (List<String>) null);
{indent}}}
{indent}
{indent}@Override
{indent}public {class_name} insert({class_name} {varname}, Connection con) {{
{indent}public {class_name} insert(final {class_name} {varname}, final Connection con) {{
{indent}{indent}logger.info("DB>> insert()");
{indent}{indent}
{indent}{indent}String sql = (
{indent}{indent}final String sql = (
{indent}{indent}{indent}"insert into {table_name} ( " +
{insert_fields}
{indent}{indent}{indent}") " +
Expand All @@ -164,19 +165,19 @@
{indent}}}
{indent}
{indent}@Override
{indent}public {class_name} insert({class_name} {varname}) {{
{indent}{indent}try (Connection con = sql2o.beginTransaction()) {{
{indent}{indent}{indent}{varname} = this.insert({varname}, con);
{indent}public {class_name} insert(final {class_name} {varname}) {{
{indent}{indent}try (Connection con = this.sql2o.beginTransaction()) {{
{indent}{indent}{indent}final {class_name} {varname}2 = this.insert({varname}, con);
{indent}{indent}{indent}con.commit();
{indent}{indent}{indent}return {varname};
{indent}{indent}{indent}return {varname}2;
{indent}{indent}}}
{indent}}}
{indent}
{update}
{indent}@Override
{indent}public {class_name} save({class_name} {varname}, Connection con) {{
{indent}public {class_name} save(final {class_name} {varname}, final Connection con) {{
{idsinit}
{indent}{indent}{class_name} {varname}2 = this.{select_methods_prefix}By{methid}({idslist}, null, con);
{indent}{indent}final {class_name} {varname}2 = this.{select_methods_prefix}By{methid}({idslist}, null, con);
{indent}{indent}
{indent}{indent}if ({varname}2 == null) {{
{indent}{indent}{indent}return this.insert({varname}, con);
Expand All @@ -185,16 +186,16 @@
{indent}}}
{indent}
{indent}@Override
{indent}public {class_name} save({class_name} {varname}) {{
{indent}{indent}try (Connection con = sql2o.beginTransaction()) {{
{indent}{indent}{indent}{class_name} res = this.save({varname}, con);
{indent}public {class_name} save(final {class_name} {varname}) {{
{indent}{indent}try (Connection con = this.sql2o.beginTransaction()) {{
{indent}{indent}{indent}final {class_name} res = this.save({varname}, con);
{indent}{indent}{indent}con.commit();
{indent}{indent}{indent}return res;
{indent}{indent}}}
{indent}}}
{indent}
{indent}@Override
{indent}public void delete({idsfirm}, Connection con) {{
{indent}public void delete({idsfirm}, final Connection con) {{
{indent}{indent}logger.info("DB>> delete() - {idslog});
{indent}{indent}
{indent}{indent}String sql = "delete from {table_name} ";
Expand All @@ -210,14 +211,14 @@
{indent}
{indent}@Override
{indent}public void delete({idsfirm}) {{
{indent}{indent}try (Connection con = sql2o.beginTransaction()) {{
{indent}{indent}try (Connection con = this.sql2o.beginTransaction()) {{
{indent}{indent}{indent}this.delete({idslist}, con);
{indent}{indent}{indent}con.commit();
{indent}{indent}}}
{indent}}}
{indent}
{indent}@Override
{indent}public void deleteByModel({class_name} {varname}, Connection con) {{
{indent}public void deleteByModel(final {class_name} {varname}, final Connection con) {{
{indent}{indent}logger.info("DB>> deleteByModel()");
{indent}{indent}
{indent}{indent}String sql = "delete from {table_name} ";
Expand All @@ -235,8 +236,8 @@
{indent}}}
{indent}
{indent}@Override
{indent}public void deleteByModel({class_name} {varname}) {{
{indent}{indent}try (Connection con = sql2o.beginTransaction()) {{
{indent}public void deleteByModel(final {class_name} {varname}) {{
{indent}{indent}try (Connection con = this.sql2o.beginTransaction()) {{
{indent}{indent}{indent}this.deleteByModel({varname}, con);
{indent}{indent}{indent}con.commit();
{indent}{indent}}}
Expand All @@ -251,7 +252,7 @@
"""
{indent}{indent}
{indent}{indent}Object res_true;
{indent}{indent}Class<?> klass = {id_col_type}.class;
{indent}{indent}final Class<?> klass = {id_col_type}.class;
{indent}{indent}
{indent}{indent}if (res != null && (klass == Long.class || klass == BigDecimal.class)) {{
{indent}{indent}{indent}res_true = ((BigDecimal) res).longValue();
Expand All @@ -265,7 +266,7 @@

update_tpl = (
"""{indent}@Override
{indent}public {class_name} update({class_name} {varname}, boolean exclude_nulls, Connection con) {{
{indent}public {class_name} update(final {class_name} {varname}, final boolean exclude_nulls, final Connection con) {{
{indent}{indent}logger.info("DB>> update() - {idslog_update});
{indent}{indent}
{indent}{indent}String sql = "update {table_name} set ";
Expand All @@ -284,24 +285,24 @@
{indent}}}
{indent}
{indent}@Override
{indent}public {class_name} update({class_name} {varname}, boolean exclude_nulls) {{
{indent}{indent}try (Connection con = sql2o.beginTransaction()) {{
{indent}{indent}{indent}{varname} = this.update({varname}, exclude_nulls, con);
{indent}public {class_name} update(final {class_name} {varname}, final boolean exclude_nulls) {{
{indent}{indent}try (Connection con = this.sql2o.beginTransaction()) {{
{indent}{indent}{indent}final {class_name} {varname}2 = this.update({varname}, exclude_nulls, con);
{indent}{indent}{indent}con.commit();
{indent}{indent}{indent}return {varname};
{indent}{indent}{indent}return {varname}2;
{indent}{indent}}}
{indent}}}
{indent}"""
)

idkey_mssql_tpl = "{indent}{indent}Object res = key;"

idkey_oracle_tpl = """{indent}{indent}Object res = Sql2oUtility.getInsertedId("{table_name}", "{id0}", con, key, {id_col_type}.class);"""
idkey_oracle_tpl = """{indent}{indent}final Object res = Sql2oUtility.getInsertedId("{table_name}", "{id0}", con, key, {id_col_type}.class);"""

select_fields_tpl = (
"""{indent}{indent}String res = "";
{indent}{indent}
{indent}{indent}fields_to_ignore = fields_to_ignore
{indent}{indent}final List<String> fields_to_ignore_true = fields_to_ignore
{indent}{indent}{indent}.stream()
{indent}{indent}{indent}.map(field -> field.toUpperCase())
{indent}{indent}{indent}.collect(Collectors.toList());
Expand All @@ -310,7 +311,7 @@
)

select_field_col_tpl = (
"""{indent}{indent}if (fields_to_ignore != null && ! fields_to_ignore.contains("{col}")) {{
"""{indent}{indent}if (fields_to_ignore_true != null && ! fields_to_ignore_true.contains("{col}")) {{
{indent}{indent}{indent}res += "{initial}.{col}, ";
{indent}{indent}}}
{indent}{indent}
Expand All @@ -335,15 +336,15 @@

bymodel_where_col_tpl = (
"""{indent}{indent}if ({varname}.get{methcol}() != null) {{
{indent}{indent}{indent} sql += "{col} = :{colname} and ";
{indent}{indent}{indent}sql += "{col} = :{colname} and ";
{indent}{indent}}}
{indent}{indent}
"""
)

update_fields_col_tpl = (
"""{indent}{indent}if (! exclude_nulls || {varname}.get{methcol}() != null) {{
{indent}{indent}{indent} sql += "{col} = :{colname}, ";
{indent}{indent}{indent}sql += "{col} = :{colname}, ";
{indent}{indent}}}
{indent}{indent}
"""
Expand All @@ -358,7 +359,7 @@
idslog_col_tpl = '{varid}: " + {varid} + "'
idslog_update_col_tpl = '{varid}: " + {varname}.get{methid}() + "'
idswhere_col_tpl = '{indent}{indent}sql += "{id} = :{varid} and "; \n'
idsinit_col_tpl = '{indent}{indent}{col_type} {varid} = {varname}.get{methid}();\n'
idsinit_col_tpl = '{indent}{indent}final {col_type} {varid} = {varname}.get{methid}();\n'
idsparams_col_tpl = '{indent}{indent}{indent}query.addParameter("{varid}", {varid});\n'
insert_params_tpl = '{indent}{indent}{indent}query.bind({varname});\n'
insert_fields_col_tpl = '{indent}{indent}{indent}{indent}"{col}, " + \n'
Expand Down
2 changes: 1 addition & 1 deletion src/codefile/repository_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import {pack_model}.{class_name};
public interface {class_name}Repository {{
{indent}{class_name} {select_methods_prefix}By{methid}({idsfirm}, List<String> fields_to_ignore, Connection con);
{indent}
Expand Down Expand Up @@ -84,4 +85,3 @@ def write(config):
)

util.writeToFile(config.data_dir, config.pack_repo, config.class_name + "Repository.java", repoint)

Loading

0 comments on commit 69528a8

Please sign in to comment.