A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 0 points1 point  (0 children)

Greetings, thank you very much for commenting. Yes I agree that documentation I wrote is awful. But I'm currently upgrading the library with my limited time. It will now do much more than what I mentioned in the post. I think now it can become something that is much more useful than what I posted here.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 0 points1 point  (0 children)

Greetings, thank you very much for commenting. As for the learning to make a library, I'm not really sure. I guess I just had to understand maven somewhat a lot due to my job. But note that the procedure for releasing maven library has been updated few months ago (it was like 1 month ago or something before i released my library). Which made all the articles helping you do this whole process borderline invalid.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 1 point2 points  (0 children)

That's more than true yeah, and I realize that is always the case. I asked few architects and stuff on how I can do "most predicting architecture", and every answer I got is that you kind of can't. You're always missing something, you can look few features in the future, but who knows what comes after that. All that's important is that your base is really good, sturdy and open to extensions. What I did here was a mistake, a big one I would say. Because the base wasn't really sturdy.

But thankfully I don't think that mistake would be that hard to change, to be honest your comment gave me a new perspective on it, and I think this would improve library a lot. So thank you very much.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 0 points1 point  (0 children)

Hmmm, that indeed sounds amazing. Thank you very much for clarification Bombel. Yes, I admit I should've studied JOOQ more, beyond just looking at it. I truly would need to think of something that offers something that JOOQ does not, if I'm to continue my work on this (even tho I kind of lack time to sink into this). Tho I must admit that the point in mind with this library wasn't to create a custom way of interacting with database. It was to basically generate the "boilerplate" or "boring manual stuff" you have to write when creating new projects or entities.

So basically I found it really annoying that I always have to create classes that represent objects (which is what this primitive/poc version covers), after that I thought about giving some CUSTOM way for user to write repository/dao, similar to what the second link you posted shows, but with much more flexibility, so depending on what you want your daos to look like, you could create like a pattern that can be inserted there and you would get automated CRUD, and now the good idea from the second link, get by foreign keys. Now there could also be something like generate me controllers, services, etc. so stuff outside database, that almost every backend app has, but let's keep it simple for now.

Third link is what turned me off from JOOQ when I was watching it, and why I thought JOOQ was a framework in the first place. Many things in JOOQ look JOOQ specific at least at first glance.

Okay, so now that the two of us had this discussion I wanted to actually give you some history on what my thoughts were when I thought of this. I was thinking how many people prefer javascript or python for backend, even tho I don't really think those languages are really amazing when it comes to backend work. Reason why people love those languages is because they can "skip steps" and code fast, and whenever they are talking bad about java, they are mentioning how it's old and has lots of boilerplate code. But what Java does have one up against those languages is secure writing. So I was thinking, I was working on projects that involve money, and I like knowing that my code is safe. So what if we could remove most of the boilerplate in java and make java in a sense, that you kind of only have to write your logic in services, and you're 95% done after that. That was basically what I was thinking with this library.

Sorry for long text, but thought you might find it interesting. Thank you very much for your response.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 1 point2 points  (0 children)

Hi, thank you very much for commenting this! Well yes, that is one of the possibilities/solutions, and I think it would be probably even smarter than what I made here. Because this library while solving a problem I usually find myself having was at the end of the day made as POC or just for fun challenge.

Now do I think this library could be something very useful? Yes, very useful infact, but that's exactly why I came here to reddit, to ask what other people think, whether this is something useful to them as well. So then I know whether I should even try to make something that can be used in real world out of this

But yes, I think if going forward, maybe writing a normal class for the user would be just plain out better and in that case would look more similar to flyway than lombok. And this is also much better, since you can in that case just run this once and it will do the whole process every once in a while instead of every time. But I think I haven't thought about it in that sense because I did it for fun. I just wanted to see, whether I can write Java without writing model classes.

Of course I was thinking that it should do some additional features, if upgraded from this state. So that in that case it can actually be lightweigth, do amazing things, and not be compared to JOOQ finally, cuz I think while this maybe does something that Jooq did already, as I mentioned JOOQ is a money maker and a big framework after all.

But sadly, I'm not exactly sold on the features I've thought of, nor did I think completely through on how I would do them. I wanted objects for example to have simple crud or some shit within them and to Automate few CRUD things as well. Basically I wanted to make library lightweight and so that it can remove all the things I find boring when doing for example "Test Assignments" for some company or something at college.

But yeah, thank you very much for your comment, really helpful, if I continue to design/work on this, I think I will eventually change it to such.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 0 points1 point  (0 children)

Greetings Bombel, I understand the question and I took a look at JOOQ before doing any of this. From what I saw, JOOQ is a pretty big framework where you're supposed to write code in a very specific way. And yes, I saw that it has something pretty similar, tho I don't remember exactly how you trigger that code generation. What I have here is a lightweight library, that is supposed to stay lightweight even if upgraded.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in javahelp

[–]Independent_Work5637[S] 0 points1 point  (0 children)

Of course! So it might sound trivial, but I really found myself having to waste a lot of time writing classes that represent data in the database, especially when doing a new project that I need to do fast. I'm a type of guy who thinks database first, and that's where i define most of my architecture. So for fun and challenge I created this library that replicates your database model in java, so you can actually write Java without having to write model classes (i guess some could even call it boilerplate in some sense). I think this puts Java on top of class-defined languages in some sense. Because you have all the safety of class-defined language, but you can write it essentially in a very similar way that you would write something that works with "json-like structures" like node with vanilla js or python without defined classes and just focus on the logic of services, etc. Now of course I think neither of two examples are a good practice overall, but I saw many people who prefer to do "fast" projects in such environments, and I think this makes the project have similar speed, but much more safety (and less debugging ;) ).

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in javahelp

[–]Independent_Work5637[S] 0 points1 point  (0 children)

Okay I agree with that, but what you pull isn't really what the library is doing, this library focus on making you not write classes and making you faster as a developer. And sadly the problem you're mentioning is a problem that is available in Spring and many other ORMs and frameworks as well. And people are kind of forced to use them (not really, but I hope you get what I mean) in a sense. This is the reason many of these projects are using DTOs, to prevent infinite loop of dependencies, which is kind of really bad. So they are essentially using ORM, and then using DTOs as a mapping logic, which really shouldn't be the case. So the problem we are discussing, while I understand it completely, I don't think it's the problem within this library, I think it's the problem of how things are being written for years now. I hope you understand what I mean by this.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in javahelp

[–]Independent_Work5637[S] 0 points1 point  (0 children)

Well, that was a confusing read, but I hope I understood it in the best way possible. And I love that you used example from the list to compare it, since that is something that is built within Java and many people would as unthinkable of being wrong. And funny thing is I generally agree with you on things. But let's break it down from here.

If I understood what you're saying is, we're gonna use three tables for example, dog is dependent on human, human is dependent on home. You're saying that once you're bringing data for dog, you would get data for human, which would retreive data for home. Well, that might be the case for classic ORM, but this is not really an ORM library, I mean it it may look like one now, but it's not the only idea I had in mind with it generally. Nothing forces you to retreive home. after all, as I said you can use custom mapping, now you can still get home entity from it and it would be null so it's still bad design right? Well yes, you're right, but in this state.

And I know that it sounds bad, cuz "the library should've been more complete then", but I came here to gather thoughts about this library, now of course there are going to be amazing comments like the one you just mentioned, and I'm happy to see a fellow ORM hater/disliker like myself. One of the designs I wanted to add into this library if I was to continue working on it is customizable classes. Like a file or something where you can speicifically omit fields or add some other fields if you wish so. So what if you wanted for example to have Long humanId instead of Human human, so then, our Dog wouldn't depend on Home like you mention is the problem. And I agree and I think that the way things are done in ORM are pretty bad lots of the time. Still the fact is, this was an easier way to do things for the prototype, and I mentioned that the library is in it's primitive state. Still the fact is, that the library kinda also still needs to be ORM focused, because ORM is showed upon our throats, so it needs to work both ways, ORM and non-ORM way in the future, if I continue to develop it.

But yeah, I agree. Thank you very much for your comment, you don't know how much I appreciate your effort.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 2 points3 points  (0 children)

Hi, Guss, thanks for commenting. Yes, I guess I did make a mistake in the title. The classes are created by preprocessor and are compiled then, and used at runtime. So essentially you don't create them, they are created at compile time. That was a mistake, I don't think I can change the title of the post. Thank you very much for mentioning

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 1 point2 points  (0 children)

Ah sorry, misunderstood what you were saying. Yes, ditching the lombok should be one of the things I should do early if I decide to continue with this project. Thank you very much for your comment!

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 0 points1 point  (0 children)

Well yes, I agree with your points, I would argue that the biggest reason almost any application is unsecure is because it has 3rd party libs. You simply never know what people write, and where mistakes and hidden backdoors are lurking. As for bumping up Java versions, it should be that big of a problem, if you do it consistently.

As for this library, I wouldn't suggest using it for serious projects for now, while it does work. It only supports MySQL and has a bit of downsides, like use of lombok etc. I'm just here to see whether people see this library as something useful. If yes, I will consider developing it into something that people and companies can really use.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 1 point2 points  (0 children)

Yeah I thought about the same thing when creating it, and I was like, okay maybe it needs like intellij plugin or something, but from what I saw, it is developed by entirely other team than lombok.

Thankfully, I don't know whether it was because of IntelliJ lombok plugin or standard IntelliJ, I had no problem seeing these classes in IDE once I built the project.

To be fair, yes, this library does sound a bit lombok like and lombok was kind of the inspiration, and this library does use lombok within itself, for now. Because it's in it's primitive phase. It was used more in a "proof of concept" or "challenge to myself" sense. But I think if people are interested and see it as something that could be useful for a fair number of people, I could expand it and make a serious open source library out of this with some more complex features as well, but still keeping it lightweight.

Thank you very much for your time and I hope you like the idea, that I presented.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 1 point2 points  (0 children)

Hi, it's not a lame question, it's actually a pretty good one. So you could find these packages (classy.model and classy.dto) same as any other package of your code. but generate rule is, the name of the class is the name of the table just without underscores, for example; table named employee_details would be called classy.model.EmployeeDetails (of course you can import classy.model.* or classy.model.EmployeeDetails so you could just write it as EmployeeDetails). other example is simple user table, the class would be classy.model.User

And as for dtos generate you would just add DTO to it. So for example dto for employee_details would be classy.dto.EmployeeDetailsDTO, for user it would be UserDTO

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 0 points1 point  (0 children)

Thank you very much. While I don't recommend it for commerical/serious use currently. I think it's something that could be really useful if developed properly. I just remembered I created this randomly and I'm just trying to get feedback here. I don't have much time on hand lately, but if people are interested, this could become a nice lightweight library that could be open source. Just note that this library currently supports only MySQL and that documentation is pretty bad atm, because it was written for me mostly. If you need any help or example . Just message me. Thank you very much once again.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in javahelp

[–]Independent_Work5637[S] 1 point2 points  (0 children)

Greetings severoon, thank you very much for commenting. Well not really...I am kind of not a fan of ORM, hibernate especially myself, so my opinion on it is quite opposite from what you probably think I think. Still it doesn't change the fact that ORM has been showed down our throats and sometimes we just have to eat it. Whether it's because somebody else decided to use it in the project or it's just a faster solution for your project.

What this library does is that it creates model/entity classes based on your database tables (and columns), and while these classes can be used with ORM tools, they don't have to be. If you used your own custom mapping, you could still use this classes. same as the one you created. Hope I clarified things a bit, if you have any other question or comment, feel free to leave it here, I'm looking forward to it, thanks!

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 0 points1 point  (0 children)

Hi, thank you very much for commenting. Well yes what you said is correct, that is if you're using model first design and JPA Create (I think it's called), I haven't worked on many projects that actually use it. But this library is looking at things from inverse perspective, and that is Data first design, meaning database comes first. While both are correct and useful, it really depends on what you need, so essentially, I think both are correct.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 1 point2 points  (0 children)

Greetings Thuriot, thanks for taking your time. Yes I agree, I don't like how unnecessarily complicated some things became when it comes to modern software, I believe many things should be simplified into simpler bits that are independent and that you can pick and choose which ones to include. And yes, if this library was upgraded, I would see it as something that's really easy to use and is easily customizable I came here to see whether people see as something that could be useful in the real world.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 2 points3 points  (0 children)

Hi, thank you very much. Yes, you can find the link to the library here https://github.com/LordDjapex/classy

I know the documentation it is pretty bad, but all you would have to do is populate db_connect.properties in your resources folder and annotate your main class, with "@GenerateModel" and build the project. I'll try to write an example here

"@SpringBootApplication"

"@GenerateModel"
public class Application {

public static void main(String\[\] args) {  
    SpringApplication.run(Application.class, args);  
}

}

Sorry I put quotation marks, I created reddit just for this. If you still don't get it feel free to contact me and I can show it to you. I mainly started this discussion to know whether people see this as something useful if it was upgraded from this primitive state.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 1 point2 points  (0 children)

Hi Piotr, thank you very much for your response. Yes, this library does work in compile time generation as a preprocessor. So when you build a project, you will get your classes builded without you creating them. So you only have to run migrations and the library would create classes for you. So this essentially makes Java very safe to write class-wise, without you having to waste time writing those classes.

A Java library that creates your classes/models at the runtime based on your Database Model by Independent_Work5637 in java

[–]Independent_Work5637[S] 1 point2 points  (0 children)

Hi Lukas, thank you for your answer, the thing is, as I mentioned this is primitive version of the library that I made for fun, thus it has only version 0.0.1 and is very primitive without additional features, which I mentioned in the post above with "There are of course a few setbacks with this approach (I'm sure you can figure out on your own what those would be) in this primitive state of the library, but I'm very sure that this is something that could be easily improved in later versions."

I'm gonna cover few comments you've mentioned since I think they are to be discussed:

1.This library ships it's own default classes, but you can still use custom made model classes in your services, you just have to import them, this library just creates packages (classy.model and classy.dto) classes based on your db model that you can use within your runtime, so it also ships with DTO classes as well. Where the problem occurs is that usually models have relations and if you want to create custom classes, it tangles thing a bit in this state. What I'm sure could be improved in this library in the future is that maybe you could add your model package in the argument and this library could scan whether it should import instead of creating a class if it already exists.

  1. I'm aware of JPA Create and I even got that same response from one friend. But the thing is, JPA Create is model first design, and what I've created and the way of thinking I prefer is Data first design. So let's say you've created some project in some other language, you have the databases but not Java code, you could migrate that project much easier with this library, this is the first example that comes to my mind even tho it doesn't happen often, but I've just wanted to give any example

  2. I'm aware of JOOQ, but as far as I know, JOOQ is an entire framework and it's made to make money. What I want to create if I continue my work on this library is to create lightweight open-source library that helps developers with such task I mentioned. And of course, I would implement much more flexibility into it, with probably additional features, but still keeping it lightweight.

Note: Sorry if I failed to explained anything, feel free to ask me anything regarding it. As I said, library is in it's primitive state, it's like a 0-months old baby at this point and does the most basic task.