OHibernate


Source link: https://github.com/10uroi/OHibernate

OHibernate


1.0.9

SQLite Connection for Android. ORM tool for Android devices. First ORM with Geometric-Spatial data support for Android operating systems.

There is relational table support. OneToOne and OneToMany are fully supported. OHQL support for simple inquiries.

Log

v1.0.8 -> Solved single quotes problem.
v1.0.9 -> Folder created automatically.

##Installation

To use the library, first include it your project using Gradle


 allprojects {

repositories {

 jcenter()

 maven {
 url "https://jitpack.io" 
}

}

  
}
 

and:


 dependencies {

 compile 'com.github.10uroi:OHibernate:1.0.9'
  
}
 

##How to use

###Attached into the "MainActivity" class public class MainActivity extends AppCompatActivity {


  //I set the database path and the name

public static final String DATABASE_EXTERNAL = Environment.getExternalStorageDirectory().getPath();
 //external

public static final String DATABASE_SUB = "/folderName/";

public static final String DATABASE_DB_PATH = DATABASE_EXTERNAL + DATABASE_SUB;

public static final String DATABASE_DATA_NAME = "databaseName.sqlite";

@Override
protected void onCreate(Bundle savedInstanceState) {

 super.onCreate(savedInstanceState);

 OHibernateConfig.DB_PATH = DATABASE_DB_PATH; // DATABASE PATH
OHibernateConfig.DB_NAME = DATABASE_DATA_NAME; // DATABASE NAME

}
  
}
 

###We are creating the "ExampleBean" class @Entity(TABLE_NAME = "example", TABLE_OPERATION = Entity.TABLE_OPERATION_TYPE.DROP_AND_CREATE) public class ExampleBean {

  @Id(PRIMARY_KEY_AUTOINCREMENT = true)
private Integer id;
 private String name;
 private String surname;
 private int age;
 @Column(NAME = "active") //column customization
private boolean status;
 @Column(DATETIME = true) //column customization
private String datetime;

//GETTER - SETTER  
}
 

###We are creating the "ExampleBeanDAO" class public class ExampleBeanDAO {

  //Automatic Transactions
  OHibernate<ExampleBean> oHibernate = new OHibernate<>(ExampleBean.class);

 public void insert(ExampleBean exampleBean){

 try {

  oHibernate.insert(exampleBean);
 // Returns the id of the object
 
}
 catch (Exception e) {

  e.printStackTrace();

  Log.e("Error",e.getMessage());

 
}

}

 public void update(ExampleBean exampleBean){

 try {

  oHibernate.update(exampleBean);

 
}
 catch (Exception e) {

  e.printStackTrace();

  Log.e("Error",e.getMessage());

 
}

}

 public void delete(ExampleBean exampleBean){

 try {

  oHibernate.delete(exampleBean);

 
}
 catch (Exception e) {

  e.printStackTrace();

  Log.e("Error",e.getMessage());

 
}

}

 public ExampleBean select(Integer id){

 try {

  return (ExampleBean) oHibernate.where("id",id).select();

 
}
 catch (Exception e) {

  e.printStackTrace();

  Log.e("Error",e.getMessage());

 
}

 return null;

}

 public ArrayList<ExampleBean> selectAll(){

 try {

  return (ArrayList<ExampleBean>) oHibernate.selectAll();

 
}
 catch (Exception e) {

  e.printStackTrace();

  Log.e("Error",e.getMessage());

 
}

 return null;

}

 public ArrayList<ExampleBean> selectAll(String surname){

 try {

  return (ArrayList<ExampleBean>) oHibernate.where("surname",surname).limit(5).selectAll();
 // custom
 
}
 catch (Exception e) {

  e.printStackTrace();

  Log.e("Error",e.getMessage());

 
}

 return null;

}

 public ExampleBean selectCustom(String name,String surname){

 try {

  return (ExampleBean) oHibernate.where("name",name).and().where("surname",surname, LIKE_TYPE.BOTH).select();
 // custom
 
}
 catch (Exception e) {

  e.printStackTrace();

  Log.e("Error",e.getMessage());

 
}

 return null;

}
  
}
 

Relational tables

Example OneToMany

User Address
@Entity(TABLE_NAME = "users", TABLE_OPERATION = Entity.TABLE_OPERATION_TYPE.CREATE)  public class User {

@Id(PRIMARY_KEY_AUTOINCREMENT = true)
private Integer id;
 private String firstName;
 private String lastName;
 @OneToMany(JoinColumn = "user_id", Cascade = CascadeType.ALL, Fetch = FetchType.EAGER)
private ArrayList<Address> addresses;
 ...
//Getter - Setter 
}

 </code>  </pre> </td> <td style="padding:0; margin:0; border:none; width:50%;">
<pre lang="java"><code class="language-java">@Entity(TABLE_NAME = "addresses",TABLE_OPERATION = Entity.TABLE_OPERATION_TYPE.CREATE) public class Address {

 @Id(PRIMARY_KEY_AUTOINCREMENT = true)
private Integer id;
 private String county;
 @Column(NAME="phone_number")
private Long phoneNumber;
 private Integer user_id;
 ...
//Getter - Setter 
}

</code></pre> </td>
 
### DB Tables
users addresses
id firstname lastname
</td> <td style="padding:0; margin:0; border:none;">
id </td> <td style="padding:0; margin:0; border:none;">
county </td> <td style="padding:0; margin:0; border:none;">
phone_number </td> <td style="padding:0; margin:0; border:none;">
user_id </td> 
1 Onur Ciner ?? 1 Ankara 05554443322 1
</td> <td style="padding:0; margin:0; border:none;">
</td>  <td style="padding:0; margin:0; border:none;">  </td> <td style="padding:0; margin:0; border:none;">  ?? </td> <td style="padding:0; margin:0; border:none;">
2 </td> <td style="padding:0; margin:0; border:none;">
?stanbul </td> <td style="padding:0; margin:0; border:none;">
05554443311 </td> <td style="padding:0; margin:0; border:none;">
1 </td> 

OHQL (The OHibernate Query Language)

Single Select

User user = (User) new OQuery()  .addEntity(User.class)  //=>Returns a String if entity is not added  .Select("*")  .From("users")
 //=> "users"->table name  .Where("id",2)  .getSingleResult();

//=> Fetch user with id 2 in the users table 

List Select

ArrayList<User> users = new OQuery()  .addEntity(User.class)  //=>Returns a String if entity is not added  .Select("*")  .From("users")
 //=> "users"->table name  .list();

  //=> Brings all users in the users table 

Insert Query

new OQuery()  .SetParameter("firstName","Onur")  .SetParameter("lastName","Ciner")  .Insert("users");

//=> "users"->table name 

Insert Entity Query

Users user = new Users();

  //=>The object is created user.setFirstName("Onur");
 user.setLastName("Ciner");
 new OQuery().InsertEntity("users",user);
 //=> "users"->table name 

Update Query

new OQuery()  .SetParameter("firstName", "Selçuk")  .SetParameter("lastName", "Uzunsoy")  .Where("id", 15)
 //=> User with id 15 will be updated  .Update("users");

  //=> "users"->table name 

Update Entity Query

Users user = OQuery().Select...;
//=> Object brought user.setFirstName("Onur");
 user.setLastName("Ciner");
 new OQuery().UpdateEntity("users",user);
 //=> "users"->table name 

Delete Query

new OQuery()  .Where("id",15)  //=> User with id 15 will be deleted  .Delete("users");
 //=> "users"->table name 

DeleteAll Query

new OQuery()  .DeleteAll("users");
 //=> All users in the users table will be deleted 

Resources

Chuck is a simple in-app HTTP inspector for Android OkHttp clients. Chuck intercepts and persists all HTTP requests and responses inside your application, and provides a UI for inspecting their content.

An Android library that takes the standard Android Toast and takes it to the next level with a variety of styling options that gives your app and user experience that little extra unique feeling! Style your toast either by code or in styles.xml!

A Powerful AlphabetIndex FastScroller for Android's RecyclerView! Its shows Alphabets over scrolling the recycle view from A-Z.

A lightweight RxJava2 wrapper for the Android Firebase client SDK, the user is expected to own the lifecycle of an asynchronous request via RxJava2 Disposable handling, however elements in this library will properly unregister listeners when a Publisher is cancelled, except in the case of value setting where it is only possible to register a listener when making the request. In this case the emitter is checked for it's subscription state.

Whilst the FirebaseDatabase api is mirrored with RxFirebaseDatabase it only really uses the database reference, this is so that the reference hierarchy can easily be traversed through child and parent elements. Methods requiring FirebaseDatabase obtain this from the DatabaseReference and allow you to chain further requests by returning itself.

This library depends on RxTasks and RxJava2 to provide appropriate api responses. Therefore asynchronous responses will return, Single, Completable and Flowable respectively.

Two step picker dialog for Android that helps you easily pick nested data on android.

A implementaion of scrollview, gesture and linearlayout.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes