simplify interface BDD...

This commit is contained in:
Edouard DUPIN 2022-06-21 00:03:18 +02:00
parent 5cb6190f8e
commit 6d07dcf15d
9 changed files with 331 additions and 249 deletions

View File

@ -210,11 +210,11 @@ public class DataResource {
entry.disconnect();
}
static String saveTemporaryFile(InputStream uploadedInputStream, long idData) {
public static String saveTemporaryFile(InputStream uploadedInputStream, long idData) {
return saveFile(uploadedInputStream, DataResource.getTmpFileInData(idData));
}
static void removeTemporaryFile(long idData) {
public static void removeTemporaryFile(long idData) {
String filepath = DataResource.getTmpFileInData(idData);
if (Files.exists(Paths.get(filepath))) {
try {
@ -227,7 +227,7 @@ public class DataResource {
}
// save uploaded file to a defined location on the server
static String saveFile(InputStream uploadedInputStream, String serverLocation) {
public static String saveFile(InputStream uploadedInputStream, String serverLocation) {
String out = "";
try {
OutputStream outpuStream = new FileOutputStream(new File(

View File

@ -76,39 +76,6 @@ public class NodeInterface {
ORDER BY node.name
*/
public static List<NodeSmall> get(String typeInNode) {
System.out.println(typeInNode + " get");
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
List<NodeSmall> out = new ArrayList<>();
String query = "SELECT node.id," +
" node.name," +
" node.description," +
" node.parent_id," +
" (SELECT GROUP_CONCAT(tmp.data_id SEPARATOR '-')" +
" FROM cover_link_node tmp" +
" WHERE tmp.deleted = false" +
" AND node.id = tmp.node_id" +
" GROUP BY tmp.node_id) AS covers" +
" FROM node" +
" WHERE node.deleted = false " +
" AND node.type = ?" +
" ORDER BY node.name";
try {
PreparedStatement ps = entry.connection.prepareStatement(query);
int iii = 1;
ps.setString(iii++, typeInNode);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
out.add(new NodeSmall(rs));
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}
entry.disconnect();
entry = null;
System.out.println("retrieve " + out.size() + " " + typeInNode);
return out;
}
public static NodeSmall getWithId(String typeInNode, long id) {
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
@ -276,131 +243,6 @@ public class NodeInterface {
return createNode(typeInNode, name, null, parentId);
}
static private String multipartCorrection(String data) {
if (data == null) {
return null;
}
if (data.isEmpty()) {
return null;
}
if (data.contentEquals("null")) {
return null;
}
return data;
}
static public Response uploadCover(String typeInNode,
Long nodeId,
String file_name,
InputStream fileInputStream,
FormDataContentDisposition fileMetaData
) {
try {
// correct input string stream :
file_name = multipartCorrection(file_name);
//public NodeSmall uploadFile(final FormDataMultiPart form) {
System.out.println("Upload media file: " + fileMetaData);
System.out.println(" - id: " + nodeId);
System.out.println(" - file_name: " + file_name);
System.out.println(" - fileInputStream: " + fileInputStream);
System.out.println(" - fileMetaData: " + fileMetaData);
System.out.flush();
NodeSmall media = getWithId(typeInNode, nodeId);
if (media == null) {
return Response.notModified("Media Id does not exist or removed...").build();
}
long tmpUID = DataResource.getTmpDataId();
String sha512 = DataResource.saveTemporaryFile(fileInputStream, tmpUID);
Data data = DataResource.getWithSha512(sha512);
if (data == null) {
System.out.println("Need to add the data in the BDD ... ");
System.out.flush();
try {
data = DataResource.createNewData(tmpUID, file_name, sha512);
} catch (IOException ex) {
DataResource.removeTemporaryFile(tmpUID);
ex.printStackTrace();
return Response.notModified("can not create input media").build();
} catch (SQLException ex) {
ex.printStackTrace();
DataResource.removeTemporaryFile(tmpUID);
return Response.notModified("Error in SQL insertion ...").build();
}
} else if (data.deleted == true) {
System.out.println("Data already exist but deleted");
System.out.flush();
DataResource.undelete(data.id);
data.deleted = false;
} else {
System.out.println("Data already exist ... all good");
System.out.flush();
}
// Fist step: retrieve all the Id of each parents:...
System.out.println("Find typeNode");
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
long uniqueSQLID = -1;
// real add in the BDD:
try {
// prepare the request:
String query = "INSERT INTO cover_link_node (create_date, modify_date, node_id, data_id)" +
" VALUES (now(3), now(3), ?, ?)";
PreparedStatement ps = entry.connection.prepareStatement(query,
Statement.RETURN_GENERATED_KEYS);
int iii = 1;
ps.setLong(iii++, media.id);
ps.setLong(iii++, data.id);
// execute the request
int affectedRows = ps.executeUpdate();
if (affectedRows == 0) {
throw new SQLException("Creating data failed, no rows affected.");
}
// retreive uid inserted
try (ResultSet generatedKeys = ps.getGeneratedKeys()) {
if (generatedKeys.next()) {
uniqueSQLID = generatedKeys.getLong(1);
} else {
throw new SQLException("Creating user failed, no ID obtained (1).");
}
} catch (Exception ex) {
System.out.println("Can not get the UID key inserted ... ");
ex.printStackTrace();
throw new SQLException("Creating user failed, no ID obtained (2).");
}
} catch (SQLException ex) {
ex.printStackTrace();
entry.disconnect();
return Response.serverError().build();
}
// if we do not une the file .. remove it ... otherwise this is meamory leak...
DataResource.removeTemporaryFile(tmpUID);
System.out.println("uploaded .... compleate: " + uniqueSQLID);
return Response.ok(getWithId(typeInNode, nodeId)).build();
} catch (Exception ex) {
System.out.println("Cat ann unexpected error ... ");
ex.printStackTrace();
}
return Response.serverError().build();
}
static public Response removeCover(String typeInNode, Long nodeId, Long coverId) {
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
String query = "UPDATE `cover_link_node` SET `modify_date`=now(3), `deleted`=true WHERE `node_id` = ? AND `data_id` = ?";
try {
PreparedStatement ps = entry.connection.prepareStatement(query);
int iii = 1;
ps.setLong(iii++, nodeId);
ps.setLong(iii++, coverId);
ps.executeUpdate();
} catch (SQLException throwables) {
throwables.printStackTrace();
entry.disconnect();
return Response.serverError().build();
}
entry.disconnect();
return Response.ok(getWithId(typeInNode, nodeId)).build();
}
static public Response put(String typeInNode, Long id, String jsonRequest) {
ObjectMapper mapper = new ObjectMapper();
@ -461,22 +303,4 @@ public class NodeInterface {
}
static public Response delete(String typeInNode, Long nodeId) {
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
String query = "UPDATE `node` SET `modify_date`=now(3), `deleted`=true WHERE `id` = ? AND `type` = ?";
try {
PreparedStatement ps = entry.connection.prepareStatement(query);
int iii = 1;
ps.setLong(iii++, nodeId);
ps.setString(iii++, typeInNode);
ps.executeUpdate();
} catch (SQLException throwables) {
throwables.printStackTrace();
entry.disconnect();
return Response.serverError().build();
}
entry.disconnect();
return Response.ok().build();
}
}

View File

@ -25,8 +25,8 @@ public class Album extends Playlist {
public Album() {
}
public Album(ResultSet rs) {
super(rs);
protected Album(String tableName, ResultSet rs) {
super(tableName, rs);
int iii = super.getRsCount();;
try {
this.publication = rs.getDate(iii++);
@ -38,6 +38,10 @@ public class Album extends Playlist {
}
}
public Album(ResultSet rs) {
this("album", rs);
}
@Override
public int getRsCount() {
return super.getRsCount() + 1;
@ -50,14 +54,17 @@ public class Album extends Playlist {
}
@Override
public String getTableSql(String tableName) {
return super.getTableSql(tableName).replaceAll("<<<TABLE_ADDITION>>>", """
public String getTableSqlModel() {
return super.getTableSqlModel().replaceAll("<<<TABLE_ADDITION>>>", """
`publication` timestamp(3) NULL COMMENT 'death date of the artist',
<<<TABLE_ADDITION>>>
""");
}
@Override
public String getTableSql() {
return getTableSql("album").replaceAll("<<<.*>>>", "");
}
protected String getQueryString() {
return super.getQueryString().replaceAll("<<<ELEMENT_LIST>>>", ", <<<TABLE_NAME>>>.publication <<<ELEMENT_LIST>>>");
}
Object createObject(ResultSet rs) {
return new Album(rs);
}
}

View File

@ -26,10 +26,10 @@ public class Artist extends NodeSmall {
Date death = null;
public Artist() {
super("artist");
}
public Artist(ResultSet rs) {
super(rs);
public Artist(String tableName, ResultSet rs) {
super("artist", rs);
int iii = super.getRsCount();;
try {
@ -53,6 +53,9 @@ public class Artist extends NodeSmall {
ex.printStackTrace();
}
}
public Artist(ResultSet rs) {
this("artist", rs);
}
@Override
public int getRsCount() {
return super.getRsCount() + 4;
@ -63,8 +66,8 @@ public class Artist extends NodeSmall {
", firstName=" + firstName + ", surname=" + surname + ", birth=" + birth + ", death=" + death + "]";
}
@Override
public String getTableSql(String tableName) {
return super.getTableSql(tableName).replaceAll("<<<TABLE_ADDITION>>>", """
public String getTableSqlModel() {
return super.getTableSqlModel().replaceAll("<<<TABLE_ADDITION>>>", """
`firstName` varchar(256) NOT NULL,
`surname` varchar(256) NOT NULL,
`birth` timestamp(3) NULL COMMENT 'birth date of the artist',
@ -72,8 +75,11 @@ public class Artist extends NodeSmall {
<<<TABLE_ADDITION>>>
""");
}
@Override
public String getTableSql() {
return getTableSql("artist").replaceAll("<<<.*>>>", "");
}
protected String getQueryString() {
return super.getQueryString().replaceAll("<<<ELEMENT_LIST>>>", ", <<<TABLE_NAME>>>.firstName, <<<TABLE_NAME>>>.surname, <<<TABLE_NAME>>>.birth, <<<TABLE_NAME>>>.death <<<ELEMENT_LIST>>>");
}
Object createObject(ResultSet rs) {
return new Album(rs);
}
}

View File

@ -20,10 +20,15 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
public class Gender extends NodeSmall {
public Gender() {
super("gender");
}
protected Gender(String tableName, ResultSet rs) {
super(tableName, rs);
}
public Gender(ResultSet rs) {
super(rs);
this("gender", rs);
// nothing to do...
}
@Override
@ -35,8 +40,4 @@ public class Gender extends NodeSmall {
return "Gender [id=" + id + ", name=" + name + ", description=" + description + ", covers=" + covers + "]";
}
@Override
public String getTableSql() {
return getTableSql("gender").replaceAll("<<<.*>>>", "");
}
}

View File

@ -1,11 +1,17 @@
package org.kar.karusic.model;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public abstract class GenericTable {
import javax.ws.rs.core.Response;
import org.kar.karusic.WebLauncher;
import org.kar.karusic.db.DBEntry;
public class GenericTable {
protected String tableName = "plopppppp";
public Long id = null;
GenericTable(String tableName) {
@ -20,6 +26,15 @@ public abstract class GenericTable {
ex.printStackTrace();
}
}
protected GenericTable(ResultSet rs) {
this.tableName = "genericTable";
int iii = 1;
try {
this.id = rs.getLong(iii++);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
protected List<Long> getListOfIds(ResultSet rs, int iii) throws SQLException {
String trackString = rs.getString(iii);
@ -43,6 +58,15 @@ public abstract class GenericTable {
return 1 + 1;
}
public String getQueryLinkString(String from, String to, String as) {
String out = " (SELECT GROUP_CONCAT(tmp.data_id SEPARATOR '-')" +
" FROM <<<FROM>>>_link_<<<TO>>> tmp" +
" WHERE tmp.deleted = false" +
" AND <<<TABLE_NAME>>>.id = <<<FROM>>>.<<<TABLE_NAME>>>_id" +
" GROUP BY tmp.<<<TABLE_NAME>>>_id) AS <<<AS>>>";
return out.replaceAll("<<<FROM>>>", from).replaceAll("<<<TO>>>", to).replaceAll("<<<AS>>>", as);
}
public String getTableLinkSql(String from, String to) {
return """
DROP TABLE IF EXISTS `<<<FROM>>>_link_<<<TO>>>`;
@ -71,10 +95,97 @@ public abstract class GenericTable {
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
<<<TABLE_OTHER>>>
""".replace("<<<TABLE_OTHER>>>", getTableLinkSql("<<<TABLE_NAME>>>", "data"));
""";
}
public final String getTableSql() {
return getTableSqlModel().replace("<<<TABLE_NAME>>>", tableName).replaceAll("<<<.*>>>", "");
}
public Response dbDelete(Long nodeId) {
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
String query = "UPDATE `" + tableName + "` SET `modify_date`=now(3), `deleted`=true WHERE `id` = ?";
try {
PreparedStatement ps = entry.connection.prepareStatement(query);
int iii = 1;
ps.setLong(iii++, nodeId);
ps.executeUpdate();
} catch (SQLException throwables) {
throwables.printStackTrace();
entry.disconnect();
return Response.serverError().build();
}
entry.disconnect();
return Response.ok().build();
}
public GenericTable dbGetWithId(String typeInNode, long id) {
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
String query = "SELECT " + tableName + ".id," +
" FROM " + tableName +
" WHERE " + tableName + ".deleted = false " +
" AND " + tableName + ".id = ?" +
" ORDER BY node.name";
try {
PreparedStatement ps = entry.connection.prepareStatement(query);
int iii = 1;
ps.setString(iii++, typeInNode);
ps.setLong(iii++, id);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
GenericTable out = new GenericTable(this.tableName, rs);
entry.disconnect();
entry = null;
return out;
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}
entry.disconnect();
entry = null;
return null;
}
Object createObject(ResultSet rs) {
return null;
}
protected String getQueryString() {
return "SELECT <<<TABLE_NAME>>>.id" +
" <<<ELEMENT_LIST>>>" +
" FROM <<<TABLE_NAME>>>" +
" WHERE <<<TABLE_NAME>>>.deleted = false ";
}
public List<Object> get() {
System.out.println("'" + tableName + "' get ...");
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
List<Object> out = new ArrayList<>();
String query = getQueryString();
/*"SELECT <<<TABLE_NAME>>>.id" +
" <<<ELEMENT_LIST>>>" +
" node.name," +
" node.description," +
" node.parent_id," +
" (SELECT GROUP_CONCAT(tmp.data_id SEPARATOR '-')" +
" FROM cover_link_node tmp" +
" WHERE tmp.deleted = false" +
" AND node.id = tmp.node_id" +
" GROUP BY tmp.node_id) AS covers" +
" FROM <<<TABLE_NAME>>>" +
" WHERE <<<TABLE_NAME>>>.deleted = false ";
*/
try {
PreparedStatement ps = entry.connection.prepareStatement(query);
int iii = 1;
ResultSet rs = ps.executeQuery();
while (rs.next()) {
out.add(this.createObject(rs));
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}
entry.disconnect();
entry = null;
System.out.println("retrieve " + out.size() + " '" + tableName + "'");
return out;
}
}

View File

@ -12,10 +12,21 @@ CREATE TABLE `node` (
) AUTO_INCREMENT=10;
*/
import java.io.IOException;
import java.io.InputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.kar.karusic.WebLauncher;
import org.kar.karusic.api.DataResource;
import org.kar.karusic.db.DBEntry;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@ -53,11 +64,144 @@ public class NodeSmall extends GenericTable {
return super.getRsCount() + 3;
}
@Override
public String getTableSql(String tableName) {
return super.getTableSql(tableName).replaceAll("<<<TABLE_ADDITION>>>", """
public String getTableSqlModel() {
return super.getTableSqlModel().replaceAll("<<<TABLE_ADDITION>>>", """
`name` text CHARACTER SET utf8mb3 COLLATE utf8_general_ci NOT NULL,
`description` text CHARACTER SET utf8mb3 COLLATE utf8_general_ci,
<<<TABLE_ADDITION>>>
""").replaceAll("<<<TABLE_OTHER>>>", getTableLinkSql(tableName, "data"));
""").replaceAll("<<<TABLE_OTHER>>>", getTableLinkSql("<<<TABLE_NAME>>>", "cover"));
}
protected String getQueryString() {
return super.getQueryString().replaceAll("<<<ELEMENT_LIST>>>", ", <<<TABLE_NAME>>>.name, <<<TABLE_NAME>>>.description, " + getQueryLinkString("<<<TABLE_NAME>>>", "cover", "covers") + " <<<ELEMENT_LIST>>>");
}
Object createObject(ResultSet rs) {
return null;//new NodeSmall(rs);
}
static private String multipartCorrection(String data) {
if (data == null) {
return null;
}
if (data.isEmpty()) {
return null;
}
if (data.contentEquals("null")) {
return null;
}
return data;
}
public Response dbUploadCover(String typeInNode,
Long nodeId,
String file_name,
InputStream fileInputStream,
FormDataContentDisposition fileMetaData
) {
try {
// correct input string stream :
file_name = multipartCorrection(file_name);
//public NodeSmall uploadFile(final FormDataMultiPart form) {
System.out.println("Upload media file: " + fileMetaData);
System.out.println(" - id: " + nodeId);
System.out.println(" - file_name: " + file_name);
System.out.println(" - fileInputStream: " + fileInputStream);
System.out.println(" - fileMetaData: " + fileMetaData);
System.out.flush();
GenericTable media = dbGetWithId(typeInNode, nodeId);
if (media == null) {
return Response.notModified("Media Id does not exist or removed...").build();
}
long tmpUID = DataResource.getTmpDataId();
String sha512 = DataResource.saveTemporaryFile(fileInputStream, tmpUID);
Data data = DataResource.getWithSha512(sha512);
if (data == null) {
System.out.println("Need to add the data in the BDD ... ");
System.out.flush();
try {
data = DataResource.createNewData(tmpUID, file_name, sha512);
} catch (IOException ex) {
DataResource.removeTemporaryFile(tmpUID);
ex.printStackTrace();
return Response.notModified("can not create input media").build();
} catch (SQLException ex) {
ex.printStackTrace();
DataResource.removeTemporaryFile(tmpUID);
return Response.notModified("Error in SQL insertion ...").build();
}
} else if (data.deleted == true) {
System.out.println("Data already exist but deleted");
System.out.flush();
DataResource.undelete(data.id);
data.deleted = false;
} else {
System.out.println("Data already exist ... all good");
System.out.flush();
}
// Fist step: retrieve all the Id of each parents:...
System.out.println("Find typeNode");
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
long uniqueSQLID = -1;
// real add in the BDD:
try {
// prepare the request:
String query = "INSERT INTO " + this.tableName + "_link_cover (create_date, modify_date, " + this.tableName + "_id, cover_id)" +
" VALUES (now(3), now(3), ?, ?)";
PreparedStatement ps = entry.connection.prepareStatement(query,
Statement.RETURN_GENERATED_KEYS);
int iii = 1;
ps.setLong(iii++, media.id);
ps.setLong(iii++, data.id);
// execute the request
int affectedRows = ps.executeUpdate();
if (affectedRows == 0) {
throw new SQLException("Creating data failed, no rows affected.");
}
// retreive uid inserted
try (ResultSet generatedKeys = ps.getGeneratedKeys()) {
if (generatedKeys.next()) {
uniqueSQLID = generatedKeys.getLong(1);
} else {
throw new SQLException("Creating user failed, no ID obtained (1).");
}
} catch (Exception ex) {
System.out.println("Can not get the UID key inserted ... ");
ex.printStackTrace();
throw new SQLException("Creating user failed, no ID obtained (2).");
}
} catch (SQLException ex) {
ex.printStackTrace();
entry.disconnect();
return Response.serverError().build();
}
// if we do not une the file .. remove it ... otherwise this is meamory leak...
DataResource.removeTemporaryFile(tmpUID);
System.out.println("uploaded .... compleate: " + uniqueSQLID);
return Response.ok(dbGetWithId(typeInNode, nodeId)).build();
} catch (Exception ex) {
System.out.println("Cat ann unexpected error ... ");
ex.printStackTrace();
}
return Response.serverError().build();
}
public Response dbRemoveCover(String typeInNode, Long nodeId, Long coverId) {
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
String query = "UPDATE `" + this.tableName + "_link_cover` SET `modify_date`=now(3), `deleted`=true WHERE `" + this.tableName + "_id` = ? AND `cover_id` = ?";
try {
PreparedStatement ps = entry.connection.prepareStatement(query);
int iii = 1;
ps.setLong(iii++, nodeId);
ps.setLong(iii++, coverId);
ps.executeUpdate();
} catch (SQLException throwables) {
throwables.printStackTrace();
entry.disconnect();
return Response.serverError().build();
}
entry.disconnect();
return Response.ok(dbGetWithId(typeInNode, nodeId)).build();
}
}

View File

@ -24,9 +24,10 @@ public class Playlist extends NodeSmall {
List<Long> tracks = null;
public Playlist() {
super("playlist");
}
public Playlist(ResultSet rs) {
super(rs);
protected Playlist(String tableName, ResultSet rs) {
super(tableName, rs);
int iii = super.getRsCount();;
try {
@ -43,6 +44,9 @@ public class Playlist extends NodeSmall {
ex.printStackTrace();
}
}
public Playlist(ResultSet rs) {
this("playlist", rs);
}
@Override
public int getRsCount() {
@ -55,24 +59,14 @@ public class Playlist extends NodeSmall {
}
@Override
public String getTableSql(String tableName) {
return super.getTableSql(tableName).replaceAll("<<<TABLE_OTHER>>>", """
DROP TABLE IF EXISTS `<<<TABLE_NAME>>>_link_track`;
CREATE TABLE `<<<TABLE_NAME>>>_link_track` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'table ID',
`deleted` tinyint(1) NOT NULL DEFAULT '0',
`create_date` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`modify_date` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`<<<TABLE_NAME>>>_id` bigint DEFAULT NULL,
`track_id` bigint NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
<<<TABLE_OTHER>>>
""").replaceAll("<<<TABLE_NAME>>>", tableName);
}
@Override
public String getTableSql() {
return getTableSql("playlist").replaceAll("<<<.*>>>", "");
public String getTableSqlModel() {
return super.getTableSqlModel().replaceAll("<<<TABLE_OTHER>>>", getTableLinkSql("<<<TABLE_NAME>>>", "track"));
}
protected String getQueryString() {
return super.getQueryString().replaceAll("<<<ELEMENT_LIST>>>", ", " + getQueryLinkString("<<<TABLE_NAME>>>", "track", "tracks") + " <<<ELEMENT_LIST>>>");
}
Object createObject(ResultSet rs) {
return new Playlist(rs);
}
}

View File

@ -25,10 +25,11 @@ public class Track extends NodeSmall {
List<Long> artistId = null;
public Track() {
super("track");
}
public Track(ResultSet rs) {
super(rs);
protected Track(String tableName, ResultSet rs) {
super(tableName, rs);
int iii = super.getRsCount();;
try {
this.genderId = rs.getLong(iii++);
@ -44,6 +45,9 @@ public class Track extends NodeSmall {
ex.printStackTrace();
}
}
public Track(ResultSet rs) {
this("track", rs);
}
@Override
public int getRsCount() {
return super.getRsCount() + 4;
@ -55,28 +59,19 @@ public class Track extends NodeSmall {
}
@Override
public String getTableSql(String tableName) {
return super.getTableSql(tableName).replaceAll("<<<TABLE_ADDITION>>>", """
public String getTableSqlModel() {
return super.getTableSqlModel().replaceAll("<<<TABLE_ADDITION>>>", """
`genderId` bigint NULL,
`dataId` bigint NULL,
<<<TABLE_ADDITION>>>
""").replaceAll("<<<TABLE_OTHER>>>", """
DROP TABLE IF EXISTS `<<<TABLE_NAME>>>_link_artist`;
CREATE TABLE `<<<TABLE_NAME>>>_link_artist` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'table ID',
`deleted` tinyint(1) NOT NULL DEFAULT '0',
`create_date` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`modify_date` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`<<<TABLE_NAME>>>_id` bigint DEFAULT NULL,
`artist_id` bigint NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
<<<TABLE_OTHER>>>
""").replaceAll("<<<TABLE_NAME>>>", tableName);
}
@Override
public String getTableSql() {
return getTableSql("track").replaceAll("<<<.*>>>", "");
""").replaceAll("<<<TABLE_OTHER>>>", getTableLinkSql("<<<TABLE_NAME>>>", "artist"));
}
protected String getQueryString() {
return super.getQueryString().replaceAll("<<<ELEMENT_LIST>>>", ", <<<TABLE_NAME>>>.genderId, <<<TABLE_NAME>>>.dataId, " + getQueryLinkString("<<<TABLE_NAME>>>", "artist", "artists") + " <<<ELEMENT_LIST>>>");
}
Object createObject(ResultSet rs) {
return new Track(rs);
}
}